无法从给定的插入查询中插入mysql数据库中的值..它是否正确

时间:2014-03-26 01:11:01

标签: php mysql sql syntax-error

我试图从其他页面发布的变量中插入mysql数据库中的值并将其保存在数据库中,但代码用于在mysql数据库中插入值但查询无法正常显示错误编辑。

解析错误:语法错误,意外''。$ Type_of_leave。''(T_CONSTANT_ENCAPSED_STRING)在第53行的C:\ wamp \ www \ saveetha \ staff \ process_leave.php

如何使用查询进行插入                                                                    新假                                                   

            $con=mysqli_connect("localhost","root","","saveetha");
            // Check connection
            if (mysqli_connect_errno())
              {
              echo "Failed to connect to MySQL: " . mysqli_connect_error();
              }

            mysqli_query($con,"INSERT INTO `leave_details`(`leave_id`, `type`, `no_of_days`, `date_from`, `date_till`, `availed_leave`, `leave_reason`, `alternate_date`, `period`, `semester`, `fac_name`, `fac_desg`, `dept`, `approved_authority`) VALUES (
            NULL,
            "'.$Type_of_leave.'",
            "'.$No_of_days.'",
            "'.$from.'",
            "'.$upto.'",
            "'.$Leave_Availed.'",
            "'.$Reason_for_Leave.'",
            "'.$Alternate_leave.'",
            "'.$Period.'",
            "'.$Semester.'",
            "'.$Fac_name.'",
            "'.$Fac_desg.'",
            "'.$dept.'",
            "'.$Approved_by.'")");

             echo 'leave from updated !! ';
            mysqli_close($con);
            ?>

2 个答案:

答案 0 :(得分:0)

你的报价是倒退的:

mysqli_query($con,"INSERT INTO `leave_details`(`leave_id`, `type`, `no_of_days`, `date_from`, `date_till`, `availed_leave`, `leave_reason`, `alternate_date`, `period`, `semester`, `fac_name`, `fac_desg`, `dept`, `approved_authority`) VALUES (
        NULL,
        '".$Type_of_leave."',
        '".$No_of_days."',
        '".$from."',
        '".$upto."',
        '".$Leave_Availed."',
        '".$Reason_for_Leave."',
        '".$Alternate_leave."',
        '".$Period."',
        '".$Semester."',
        '".$Fac_name."',
        '".$Fac_desg."',
        '".$dept."',
        '".$Approved_by."')");

答案 1 :(得分:0)

问题出在引号中:

mysqli_query($con,"INSERT INTO `leave_details`(`leave_id`, `type`, `no_of_days`, `date_from`, `date_till`, `availed_leave`, `leave_reason`, `alternate_date`, `period`, `semester`, `fac_name`, `fac_desg`, `dept`, `approved_authority`) VALUES (
            NULL,
            '$Type_of_leave',
            '$No_of_days',
            '$from',
            '$upto',
            '$Leave_Availed',
            '$Reason_for_Leave',
            '$Alternate_leave',
            '$Period',
            '$Semester',
            '$Fac_name',
            '$Fac_desg',
            '$dept',
            '$Approved_by')");