Tue 10 Oct 2006 21:36:38
สวัสดีครับ
ขอคำแนะนำและรบกวนด้วยครับ ผม copy code insert ข้อมูล เข้า Mysql ที่ผมเขียนเอง และใช้งานได้ แล้วมาเปลี่ยนแค่ชื่อ database จากชื่อ company มาเป็น test เพราะต่างฐานข้อมูลกัน ปรากฎว่าเกิด error ดังนี้ครับ
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\appserv\www\test\login\login_regist.php on line 27
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\appserv\www\test\login\login_regist.php on line 28
Error adding to table.
พยายามหาแต่ก็หาไม่เจอครับ โดย code ที่ผมเขียนได้แก่
<?
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$dbhost="localhost";
$dbname="test";
$dbuser="root";
$dbpass="";
if(trim($_POST['code']) !=($_SESSION['ses_code']))
{
echo"<b>Code does not correct. </b>";
echo"<a href=add_index.php><b>Please add your company again !</b>";
exit;
}
$link=mysql_connect("localhost","root","");
if (!$link)
{
print("Error");
}
else
{
mysql_select_db("test",$link);
$sql="select email1 from company where email1='$email1'";
$res=mysql_query($sql, $link);
$n=mysql_num_rows($res);
mysql_free_result($res);
if($n==0)
{
$sql="INSERT into test(username, password,company, country, email1, productd, agri, alkohol, nonal, bakery, mail, fee, dtnow)
values('$email1', '$email1', '$country', '$email1', '$productd', '$agri', '$alkohol', '$nonal', '$bakery', '$mail', '$fee', CURRENT_TIMESTAMP)";
$res=mysql_query($sql, $link);
if($res==1)
print("Adding to database is OK.");
else
print("Error adding to table.");
}
else
{
print("This email already exists.");
}
}
mysql_close();
?>
รบกวนด้วยครับ
อนันต์

















