Home > Backend Development > PHP Tutorial > 小白求教!

小白求教!

WBOY
Release: 2016-06-20 12:43:37
Original
946 people have browsed it

可以用这样的形式写么?一直插入不进去
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 "<script>alert('登记成功');history.back();</script>";
  }
else
{
echo "<script>alert('登记失败!');history.back();</script>";
}
?>


回复讨论(解决方案)

/*$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());
前面都有判错,这里为何没有?

解决啦谢谢

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template