mysql沒有顯示錯誤訊息但是回傳的頁面是空白

edited 九月 2014 in 資料庫

<?php
header('content-type:text/html;charset=utf-8');
$dbServer = \"localhost\";
$dbName=\"shoping\";
$dbPassworld=\"123\";
$db=\"shop\";

if(!mysqli_connect(\"$dbServer\",\"$dbName\",\"$dbPassworld\",\"$db\"))
{
die(\"Fail\");
}
else
{
echo\"connected\";
}
$con = mysqli_connect(\"$dbServer\",\"$dbName\",\"$dbPassworld\",\"$db\");
mysqli_query($con,\"SET NAMES utf8\");
mysqli_query($con,\"SET CHARACTER_SET utf8\");
?>
<body>
<form name=\"form1\" action=\"\" method=\"post\" enctype=\"multipart/form-date\">
店家名稱:<input type=\"text\" name=\"store_name\" size=\"5\" >
店家電話:<input type=\"text\" name=\"store_phone\" size=\"10\">
店家住址:<input type=\"text\" name=\"store_live\" size=\"30\">
<input type=\"submit\" value=\"新增\">
<input type=\"reset\" value=\"重設\">
</form>
<?php
$name = $_POST['store_name'];
$live = $_POST['store_live'];
$phone = $_POST['store_phone'];

if(!isset($name)&&empty($name))
if(!isset($live)&&empty($live))
if(!isset($phone)&&empty($phone))
{
$sql = \"INSERT shoping(live,name,phone)
value('$live,$name,$phone')
\";
mysqli_query($con,$sql);
}
else
{
echo('<script language=\"JavaScript\"
alert(\"資料表不可以有空白\");
>');
}
$sql = \"SELECT * FROM shoping\";

?>


<?php
$result = mysqli_query($con,$sql);

if(mysqli_num_rows($result)>0){
echo\"<table border='1' width='100%' >
<tr>
<td><center>店家名稱</td>
<td><center>店家電話</td>
<td><center>店家住址</td>
</tr>\";

while($row=mysqli_fetch_array($result))
{
echo\"<tr>
<td>{$row['name']}</td>
<td>{$row['phone']}</td>
<td>{$row['live']}</td>
</tr>\";
}
echo\"</table>\";
}
?>


</body>

我資料表都建立啊!,為什麼回傳都空白
https://scontent-b-hkg.xx.fbcdn.net/hphotos-xpf1/v/t1.0-9/10710666_1458047284463997_5091653026688734876_n.jpg?oh=1abe793855d148c067c9206f4e36cad0&oe=548680CB <-著是我建立的資料庫Myadmin

評論

  • 我後面追加
    $sql = "INSERT shoping(live,name,phone)
    value('$live,$name,$phone')
    ";
    $result = mysqli_query($con,$sql);
    if(!$result)
    {
    die('Invalid query: ' . mysql_error());
    }
    else
    {
    echo"ok";
    }
    他最後顯示Invalid query:失敗訊息.
    (努力找錯誤中)
  • 我也確認資料庫是否有連線
    又追加指令
    if(mysqli_select_db($con,"$db"))
    {
    echo"ok";
    }
    else
    {
    echo"faile";
    }
    他回傳ok
    資料庫已經連線了
  • 資料庫沒有回應

  • <?php
    header('content-type:text/html;charset=utf-8');
    $dbServer = \"localhost\";
    $dbName=\"shoping\";
    $dbPassworld=\"123\";
    $db=\"shop\";

    if(!mysqli_connect(\"$dbServer\",\"$dbName\",\"$dbPassworld\",\"$db\"))
    {
    die(\"Fail\");
    }
    else
    {
    echo\"connected\";
    }
    echo\"<br>\";

    $con = mysqli_connect(\"$dbServer\",\"$dbName\",\"$dbPassworld\",\"$db\");
    mysqli_query($con,\"SET NAMES utf8\");
    mysqli_query($con,\"SET CHARACTER_SET utf8\");
    if(mysqli_select_db($con,$db))
    {
    echo\"ok\";
    }
    else
    {
    echo\"fail\";
    }
    error_reporting(E_ALL ^ E_DEPRECATED);
    ?>
    <body>
    <form name=\"form1\" action=\"\" method=\"post\" enctype=\"multipart/form-date\">
    店家名稱:<input type=\"text\" name=\"store_name\" size=\"5\" >
    店家電話:<input type=\"text\" name=\"store_phone\" size=\"10\">
    店家住址:<input type=\"text\" name=\"store_live\" size=\"30\">
    <input type=\"submit\" value=\"新增\">
    <input type=\"reset\" value=\"重設\">
    </form>
    <?php
    $name = $_POST['store_name'];
    $live = $_POST['store_live'];
    $phone = $_POST['store_phone'];

    if(!isset($name)&&empty($name))
    if(!isset($live)&&empty($live))
    if(!isset($phone)&&empty($phone))
    {
    $sql = \"INSERT shoping(live,name,phone)
    value('$live,$name,$phone')
    \";
    }
    else
    {
    echo\"資料表不可以有空白\";

    }
    $sql = \"SELECT * FROM shoping\";

    ?>


    <?php
    $result = mysqli_query($con,$sql);


    if(mysqli_num_rows($result)>0){
    echo\"<table border='1' width='100%' >
    <tr>
    <td><center>店家名稱</td>
    <td><center>店家電話</td>
    <td><center>店家住址</td>
    </tr>\";

    while($row=mysqli_fetch_array($result))
    {
    echo\"<tr>
    <td>{$row['name']}</td>
    <td>{$row['phone']}</td>
    <td>{$row['live']}</td>
    </tr>\";
    }
    echo\"</table>\";
    }
    $sql = \"INSERT shoping(live,name,phone)
    value($live,$name,$phone)
    \";
    $result = mysqli_query($con,$sql);
    if(!$result)
    {
    die('Invalid query: ' . mysql_error());
    }
    else
    {
    echo\"ok\";
    }

    ?>


    </body>
Sign In or Register to comment.