mysql練習一只回傳錯誤的訊息

edited 九月 2014 in PHP新手區
=====================shop.php=====================
<?phpif(isset($_POST['store_live'])&&empty($_POST['store_live']))
 if(isset($_POST['store_phone'])&&empty($_POST['store_phone']))
  if(isset($_POST['store_name'])&&empty($_POST['store_name']))
{
die('資料有沒輸入');
}else
{$sql="INSERT shoping(店家名稱,店家電話,店家住址)
     value('{$_POST['store_name']}','{$_POST['store_phone']}','{$_POST['store_live']}')";
	mysql_query($sql);
	}
?>
<body>
<?
header('content-type:text/html;charset=utf-8');
include('mysql.php');
?>
<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

	$sql = "SELECT * FROM shoping"; 
		   $result = mysql_query($sql);
if(mysql_num_rows($result)>0)
{
  echo "<hr><table><tr><td>店家名稱</td><td>店家電話</td><td>店家住址</td></tr>";
  while($row = mysql_fetch_array($result))
  {
  echo"<tr><td>{$row['店家名稱']}</td>
          <td>{$row['店家電話']}</td>
          <td>{$row['店家住址']}</td><tr>";
  } 
}echo"</table>";
?>

</body>
=====================副檔mysql.php=====================
<?php
header('content-type:text/html;charset=utf-8');
$dbServer="localhost";
$dbName="shop";
$dbUser="shoping";
$dbPass="123";
if(! @mysql_connect(";$dbServer","$dbUser","$dbPass"))
die("無法連線資料庫");
else
die("成功");
if(! @mysql_select_db($dbName))
die("無法使用資料庫");

?>
還沒送出表單就顯示錯誤訊息
顯示錯誤在""$result = mysql_query($sql);""跟""if(mysql_num_rows($result)>0)"" 怎麼樣都錯誤
回應的錯誤訊息
( ! ) Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\shop.php on line 27
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\shop.php on line 28
我該怎麼打,才是正確. 需要人指導感恩

評論

  • 1.是my sql 告知 mysql_query 未來會被棄用,只是警告訊息,解決方法提供3
    1.sever 禁止php报错
    display_errors = On =>display_errors = Off
    2. mysql_query 換成 mysqli_query , mysqli_query 用法網路查
    3.php 端 error_reporting(E_ALL ^ E_DEPRECATED);

    2.你的 $result = mysql_query($sql) 為空物件,所以 mysql_num_rows() 會錯
  • =====================副檔mysql.php=====================
    <?php
    header('content-type:text/html;charset=utf-8');
    $dbServer="localhost";
    $dbName="shop";
    $dbUser="shoping";
    $dbPass="123";
    if(! @mysql_connect(";$dbServer","$dbUser","$dbPass"))
    die("無法連線資料庫");
    if(! @mysql_select_db($dbName))
    die("無法使用資料庫");
    error_reporting(E_ALL ^ E_DEPRECATED);
    
    ?>
    
    =====================shop.php=====================
    <?PHP
    if(isset($POST['store_name'])&&empty($POST['store_name']))
    if(isset($POST['store_phone'])&&empty($POST['store_phone']))
    if(isset($POST['store_live'])&&empty($POST['store_live']))
    {
    die("有資料沒輸入");
    }
    else
    {
    $sql="INSERT shop(店家名稱,店家電話,店家住址)
         value('{$_POST['store_live']}','{$_POST['store_name']}','{$_POST['store_phone']}')";
    	 mysql_query($sql);
    }
    ?>
    <body>
    <?
    header('content-type:text/html;charset=utf-8');
    include('mysql.php');
    ?>
    <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
    $sql="SELECT *
         FROM shop";
    	 $result = mysql_query($sql);
    	 if(mysql_num_rows($result)>0)
    	 {
    	 echo"<hr><table border=1><tr><td>店家名稱</td>
    	                              <td>店家電話</td>
    								  <td>店家住址</td>
    								  </tr>";
    								  while($row=mysql_fetch_array($result))
    								  {
    								  echo"<tr><td>{$row['店家名稱']}</td>
    								           <td>{$row['店家電話']}</td>
    										   <td>{$row['店家住址']}</td>
    										   </tr>";
    								  }
    								  echo"</table>";
    	 }
    ?>
    </body>
    
    還是錯,不刑. 怎麼改都一樣
  • $sql我是給她嗎?
    $sql = "SELECT *
    FROM SHOP ";
    SELECT * FROM shop
  • Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\shop.php on line 3
  • <?PHP
    error_reporting(E_ALL ^ E_DEPRECATED);
    if(isset($POST['store_name'])&&empty($POST['store_name']))
    if(isset($POST['store_phone'])&&empty($POST['store_phone']))
    if(isset($POST['store_live'])&&empty($POST['store_live']))
    {
    die("有資料沒輸入");
    }
    else
    {
    $sql="INSERT shop(店家名稱,店家電話,店家住址)
         value('{$_POST['store_live']}','{$_POST['store_name']}','{$_POST['store_phone']}')";
    	 mysql_query($sql);
    }
    ?>
    <body>
    <?
    header('content-type:text/html;charset=utf-8');
    include('mysql.php');
    ?>
    <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
    $sql="SELECT *
         FROM shop";
    	 $result = mysql_query($sql);
    	 if(mysql_num_rows($result)>0)
    	 {
    	 echo"<hr><table border=1><tr><td>店家名稱</td>
    	                              <td>店家電話</td>
    								  <td>店家住址</td>
    								  </tr>";
    								  while($row=mysql_fetch_array($result))
    								  {
    								  echo"<tr><td>{$row['店家名稱']}</td>
    								           <td>{$row['店家電話']}</td>
    										   <td>{$row['店家住址']}</td>
    										   </tr>";
    								  }
    								  echo"</table>";
    	 }
    ?>
    </body>
    
    我改著樣,另外一行錯誤沒了. 但是著行) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\shop.php on line 32
    一值顯是錯誤訊息
  • $sql="SELECT *
    FROM shop";
    $result = mysql_query($sql);
    if(mysql_num_rows($result)>0)
  • 你的 $result = mysql_query($sql) 為空物件,所以 mysql_num_rows() 會錯
    所以,請查 mysql_query用法 ,看為何是空的 ,把 mysql_query貼在google 上,你會看到答案
  • http://stackoverflow.com/questions/21516255/warning-mysql-num-rows-expects-parameter-1-to-be-resource-boolean-given-in
    If mysql_query returns false, this is boolean
    
    系統已經給你錯誤訊息了, 還是沒辦法自己解決的話,
    你想走程式這條路, 會非常辛苦
  • 好!謝謝 runli 跟 cokellen 我會更加努力,讓自己可以搭上線
Sign In or Register to comment.