php sql insert命令无效

时间:2016-06-05 12:34:54

标签: php sql

这是我用来将代码插入sql而不是函数的代码。请帮忙!

这是整个代码。相同的插入查询命令正在使用代码的其他部分,除了这里,我很困惑,我也没有任何错误消息。

<?php
require_once 'core/db_connect.php';
$db = new DB_CONNECT();

if(isset($_POST['id']) && isset($_POST['accept'])){
$response = array();


//Pass your driver number here
$id = $_POST['id'];
$accept=$_POST['accept'];




//Get user id of the driver
//As the conceptAssignments have the driverNo instead of the user id, we need to get the user id
$result = mysql_query("UPDATE texirequest SET accept ='$accept' where id = '$id'");


    if($result){
            $response["success"] = 1;
            $response["message"] = "Data Update successful.";

// payment update
//Data





        }else{
            $response["success"] = 0;
            $response["message"] = "Could not load data".mysql_error();
            echo json_encode($response);
        }
}else{

    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
    // echoing JSON response
    echo json_encode($response);



}

                            $phone = "88";
                            $namec = "jj";
                            $named = "dd"; 
                            $amount="50";
                            $fuel="fff";
                            $did="50";
                            $reg="gg";
                            $mail="d@g";
$maild="d@t";
                            echo $phone;
                            echo $name;
$status= "pending";
echo $status;
$sql="INSERT INTO pay ( namec,mailc,did,named,maild,phone,fuel,vno,total,status)".
    "VALUES ('".$name."', '".$mail."', '".$did."', '".$named."', '".$maild."', '".$phone."', '".$fuel."', '".$reg."', '".$amount."', '".$status."');";
echo $sql;

?>

4 个答案:

答案 0 :(得分:0)

$sql="INSERT INTO pay ( namec,mailc,did,named,maild,phone,fuel,vno,total,status)".
    "VALUES ( '{$name}','{$mail}',{$did},'{$named}','{$maild}','{$phone}','{$fuel}','{$reg}',{$amount},'{$status}')";

//Check query  
echo $sql;

答案 1 :(得分:0)

如果没有错误消息等更多信息,我只能建议此查询:

$sql = "INSERT INTO pay ( namec, mailc, did, named, maild, phone, fuel, vno, total, status) VALUES ('".$name."', '".$mail."', '".$did."', '".$named."', '".$maild."', '".$phone."', '".$fuel."', '".$reg."', '".$amount."', '".$status."');";

也许跑:

echo mysqli_error($link);

这应该告诉您有关查询错误的更多信息

答案 2 :(得分:0)

$Sql = "INSERT INTO `pay`  (`namec`,`mailc`,`did`,`named`,`maild`,`phone`,`fuel`,`vno`,`total`,`total`)     VALUES('$name','$mail','$did','$named','$maild','$phone','$fuel','$reg','$amount','$status')";

//在这里发送值到数据中,$ Database是包含数据库连接的变量

$result = $Database->query($sql);   
if($result == true){
 echo "success";
}else{
 echo "failed";
}

答案 3 :(得分:0)

我错过的观点是添加查询执行。有效的代码是

var formDetails = [

        {
            "type":"textbox",
            "label":"Please enter your name",
            "id":"txt-1465133974748"
        },
        {
            "type":"select",
            "label":"Please Select Option",
            "id":"select-1865133974748",
            "fieldOptionDetails":[
            {
                "fieldLabel":"Option 1",
                "fieldValue":"1"
            },
            {
                "fieldLabel":"Option 2",
                "fieldValue":"2"
            }]
        }];

感谢您的支持。