我有“se”数据库,“client”表有 5 个字段:User_ID、User_Name、User_Pass、Name、Status
我的 table
<form name="form1" method="post" action="register.php">
<input name="txtUsername" type="text" id="txtUsername">
<input name="email" type="text" id="email">
<td><input name="txtPassword" type="password" id="txtPassword">
Register.php
$objConnect = mysql_connect("localhost","root","1234") ;
$objDB = mysql_select_db("se");
$strSQL = "INSERT INTO `client` ";
$strSQL .="(`User_ID`,`User_Name`,`User_Pass`,`Name`,`Status`) ";
$strSQL .="VALUES ";
$strSQL .="('3','".$_POST["email"]."','".$_POST["txtPassword"]."' ";
$strSQL .=",'".$_POST["txtUsername"]."','USER') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
当我运行此代码并在其中插入一些内容时,此代码将“Error Save[............]”
最佳答案
使用mysql_error()
获取与您的查询相关的错误消息:
$objQuery = mysql_query($strSQL);
if($objQuery) {
echo "Save Done.";
} else {
echo "Error Save [".$strSQL."]" . mysql_error();
}
仅供引用,mysql_*
functions shouldn't be used in new code 。它们不再维护and are officially deprecated 。请参阅red box ?了解 prepared statements相反,并使用 PDO ,或MySQLi -this article将帮助您决定哪个。如果您选择 PDO,here is a good tutorial .
您也对SQL injections持开放态度。
关于php - 如何使用dreamweaver在MySQL中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22015993/