小白求教!
程序员文章站
2022-05-22 14:43:17
...
可以用这样的形式写么?一直插入不进去
session_start();
$id=$_SESSION['id'];
$serverLink = @mysql_connect("localhost","root","root") or die("连接服务器失败!程序中断执行!");
mysql_query("set names 'gbk'");
$dbLink = @mysql_select_db("dormitory") or die("选择当前数据库失败!程序中断执行!");
$selectSQL = "select * from student where id ='$id'";
$resultSet = mysql_query($selectSQL,$serverLink);
$num=mysql_fetch_row($resultSet);
/*$name=$num[2];
$sex=$num[3];
$zy=$num[4];
$sunum=$num[5];*/
$intime=$_POST["in"];
$outtime=$_POST["out"];
$insertSQL="insert into people values("$num[2]","$num[3]","$num[4]","$num[5]",'$outtime','$intime')";
$inserted = mysql_query($insertSQL);
if($inserted)
{
$insertedRows = mysql_affected_rows();
echo "";
}
else
{
echo "";
}
?>
session_start();
$id=$_SESSION['id'];
$serverLink = @mysql_connect("localhost","root","root") or die("连接服务器失败!程序中断执行!");
mysql_query("set names 'gbk'");
$dbLink = @mysql_select_db("dormitory") or die("选择当前数据库失败!程序中断执行!");
$selectSQL = "select * from student where id ='$id'";
$resultSet = mysql_query($selectSQL,$serverLink);
$num=mysql_fetch_row($resultSet);
/*$name=$num[2];
$sex=$num[3];
$zy=$num[4];
$sunum=$num[5];*/
$intime=$_POST["in"];
$outtime=$_POST["out"];
$insertSQL="insert into people values("$num[2]","$num[3]","$num[4]","$num[5]",'$outtime','$intime')";
$inserted = mysql_query($insertSQL);
if($inserted)
{
$insertedRows = mysql_affected_rows();
echo "";
}
else
{
echo "";
}
?>
回复讨论(解决方案)
/*$name=$num[2];
有注释开始,没有注释结束。 语法错!
$insertSQL="insert into people values("$num[2]","$num[3]","$num[4]","$num[5]",'$outtime','$intime')";
双引号中出现了未转义的双引号。 语法错!
$inserted = mysql_query($insertSQL) or die(mysql_error());
前面都有判错,这里为何没有?
解决啦谢谢
上一篇: Java与MySql数据库对应类型
下一篇: sql update 语法与实例