我使用下面的代码将表单中的值插入 MySQL 数据库,但是在代码执行后 MySQL 表显示 NULL,NULL 而不是实际值。
我检查了是否从 GET 函数中正确获取了值,并且没有问题
<?php
$vac_name=$_GET['vac_name'];
$vac_comment=$_GET['vac_comment'];
echo $vac_name;
echo $vac_comment;
$con=mysql_connect("localhost","root","");
if($con==true){
echo "Connected to the database";
if(isset($_GET['vac_name'], $_GET['vac_comment'])){
mysql_select_db("attendance_db",$con);
$query = "insert into vacationtype values(LAST_INSERT_ID(),vac_name,vac_comment)";
$result=mysql_query($query,$con);
//$row=mysql_num_rows($result);
// if($row>0){
if($result==true){
echo "Successfully saved your message <br> We shall be in contact with you shortly";
}else{
echo mysql_error();
echo "Sorry the message was not saved <br> Please try again. Thank You";
} }
mysql_close($con);
}else{
echo "Cannot connect to the database";
}
?>