|
藍森林 http://www.lslnet.com 2006年8月26日 15:18
請高手看看我的程序哪裡有錯,總是無法插入數據到數據庫
運行環境:apache2.0.5+php5.0.0+mysql4.1
程序目的:通過一個up.html頁面提交,經up.php文件處理,實現把姓名錄入到mysql數據庫中。
出現的錯誤:數據表中多出一個我插入的數據行。但是裡面卻沒有內容。
第一個頁面代碼:
<html>
<body>
<form action=up.php method=post>
Frist name: <input type=text name=first size=25 maxlength=30>
Last name: <input type=text name=last size=25 maxlength=30>
<input type=submit>
<p>
</form>
</body>
</html>
第二個頁面:
<html>
<title>簡單的表單提交</title>
<body>
<?php
$connect=mysql_connect("localhost","root","r00t");
if(!$connect)echo "sorry,connect with problem";
$database_select=mysql_select_db(test);
if(!$database_select)echo "<p>您選擇的數據庫不存在,或連接出錯</p>";
$sql="insert into name (first_name,last_name) values ('$first','$last')";
;
if(mysql_query($sql))
{
echo ("your name has been add");}
else
{echo ("sorry,unable to add your name");
}
?>
</body>
</html> |
if(mysql_query($sql))
應該if(mysql_query($sql,$connect)) |
如果還不行就看你的php.ini裡面找register_global是on還是off
如果是off你的程序就應該在第二個文件頭位置加上
$first=$_POST["first"];
$last=$_POST["last"]; |
2樓正解 |
感謝大家。問題已經解決。 |
| |