简体   繁体   English

当变量存储实数值时,PHP将NULL插入MySQL数据库

[英]PHP inserting NULL into MySQL database when variables store real values

I am using the code below to insert the values from the form into the MySQL database, however after the code executes the MySQL tables displays NULL, NULL instead of the actual value. 我正在使用下面的代码将表单中的值插入MySQL数据库,但是在代码执行后,MySQL表显示NULL,而不是实际值。

I have checked to see whether the values have been correctly obtained from the GET function, and there is no problem in that either 我检查了一下是否已经从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";
    }
?>

像这样使用您的查询

insert into vacationtype values('LAST_INSERT_ID()','vac_name','vac_comment')

You mean $query="insert into vacationtype values(LAST_INSERT_ID(),'". $_GET['vac_name'] ."','". $_GET['vac_comment'] ."')" ? 您的意思是$query="insert into vacationtype values(LAST_INSERT_ID(),'". $_GET['vac_name'] ."','". $_GET['vac_comment'] ."')"吗? You have to insert the contents of $_GET. 您必须插入$ _GET的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM