建议不要使用全局变量,改一下判断语句试试。
if (empty($_POST['name'])) echo "请输入姓名";
elseif (empty($_POST['birthday']))) echo "请输入生日";///替换下面的全局变量$name,$notes,
//怎么少了$_POST['birthday']
if (empty($_POST['name'])) echo "请输入姓名";
elseif (empty($_POST['birthday']))) echo "请输入生日";///替换下面的全局变量$name,$notes,
//怎么少了$_POST['birthday']
http://community.csdn.net/Expert/TopicView1.asp?id=3566985首先看你的form是否可以正常传递变量到你的sql语句
这两段代码的区别在那里?$_POST[]是个什么变量呢?
if (empty($_POST['name'])) echo "请输入姓名";
elseif (empty($_POST['birthday']))) echo "请输入生日";if ($name==" ") echo "请输入姓名";
elseif ($birthday==" ") echo "请输入生日";
包括所有提交的POST数据
echo $sqlInsert;
echo mysql_error();把输出结果贴出来
$mylink=mysql_connect("localhost", "root", "");
mysql_select_db("userinfo", $mylink);
$sqlInsert="insert into userinfo values ('";
$sqlInsert.=$name . "',' ". "'." . "'".$notes . "')";
$result=mysql_query($sqlInsert);
echo "提交成功";Please modify code as following:
$mylink=mysql_connect("localhost", "root", "") or die("FATAL ERROR: Connection to database server failed");;
mysql_select_db("userinfo", $mylink);
if (mysql_Error($objLink))
{
return mysql_Error($objLink);
}
$sqlInsert="insert into userinfo values ('";
$sqlInsert.=$name . "',' ". "'." . "'".$notes . "')";
$result=mysql_query($sqlInsert);
if (mysql_Error($objLink))
{
return mysql_Error($objLink);
}Now, you can get all error messages, please paste them, I'll help you to solve the issue.
Following is the correct code:$mylink=mysql_connect("localhost", "root", "") or die("FATAL ERROR: Connection to database server failed");;
mysql_select_db("userinfo", $mylink);
if (mysql_Error($mylink))
{
return mysql_Error($mylink);
}
$sqlInsert="insert into userinfo values ('";
$sqlInsert.=$name . "',' ". "'." . "'".$notes . "')";
$result=mysql_query($sqlInsert);
if (mysql_Error($mylink))
{
return mysql_Error($mylink);
}
即使是这样也提交不上去,不清楚问题在那里.没有报错!
{
$mylink=mysql_connect("localhost", "root", "");
mysql_select_db("userinfo", $mylink);
$sqlInsert="insert into userinfo values ('myname', '2004-11-11', '好')"; $result=mysql_query($sqlInsert); echo "提交成功";
}
but i found the SQL sentence has some problem."insert into userinfo values ('',' '.'')"why? why i cant get the value of the variables("name" and "note")???
多了一个分号~~另外先把$name改成$_POST['name']这种形式~~另外打印一下mysql_error();
最后,注解的时候最好用汉语~~都是英文,难区分哪些是你的代码或代码产生的,哪些是你的注解
Parse error: parse error, unexpected T_VARIABLE in D:\Apache2\htdocs\write.php on line 14代码如下:
13 $sqlInsert="insert into userinfo values ('";
14 $sqlInsert.=$_POST['name'] . "',' ". "'." . "'"$_POST['notes'] . "')";
15 $result=mysql_query($sqlInsert);
<?
if ($name==" ") echo "请输入姓名";
elseif ($birthday==" ") echo "请输入生日";
else
{
$mylink=mysql_connect("localhost", "root", "");
mysql_select_db("userinfo", $mylink);
$sqlInsert="insert into userinfo values ('";
$sqlInsert.=$name . "',' ". "'." . "'".$notes . "')";
$result=mysql_query($sqlInsert);
echo "提交成功";
}
?>觉得你还是一步步来好些写成:
<?
$name = $_POST["name"];
$birthday = $_POST["birthday"];
$notes = $_POST["notes"];
if($name=="") echo"请输入姓名";
elseif($birthday=="") echo"请输入生日";
else{
$mylink=mysql_connect("localhost", "root", "");
mysql_select_db("userinfo", $mylink);
$sqlInsert = "insert into userinfo(name,birthdar,notes) values('".$name."','".$birthday."','".$notes."')";
$result=mysql_query($sqlInsert);
if($result) echo "提交成功";
else echo "插入失败";
}
?>