php,mysql错误未定义索引

时间:2015-10-06 10:00:38

标签: php mysql

if(isset($_POST["PostThisNow"])){
    $TitleOfDes = mysqli_real_escape_string($con, $_POST['TitleOfDes']);
    $TopicDec = mysqli_real_escape_string($con, $_POST['TopicDec']);
    $DesImg = mysqli_real_escape_string($con, $_POST['DesImg']);
    $category = mysqli_real_escape_string($con, $_POST['category']);
    $visiblity = mysqli_real_escape_string($con, $_POST['visiblity']);
    $PostAs = mysqli_real_escape_string($con, $_POST['PostAs']);
    $check = mysqli_real_escape_string($con, $_POST['check']);



    $qry2="INSERT INTO `c_n_discussion`
              (`TitleOfDes`, `TopicDec`, `DecImg`, `category`, 
               `visiblity`, `PostAs`, `check`) 
           VALUES ('$TitleOfDes','$TopicDec','$DesImg',
                   '$category','$visiblity','$PostAs','$check')";

    if(mysqli_query($con, $qry2)){
        echo "Records added successfully.";
    } else{
        echo "ERROR Could not able to execute $qry2. " . mysqli_error($con);
    }
}

我只想将数据插入数据库而不会出现任何错误 数据库在数据库中更新,但我不想要一些字段 该怎么办请给我解决方案 我不想填写数据库中的所有字段

3 个答案:

答案 0 :(得分:1)

$qry2="INSERT INTO `c_n_discussion`
              (`TitleOfDes`, `TopicDec`, `DecImg`) 
           VALUES ('$TitleOfDes','$TopicDec','$DesImg')";

删除您不想要的字段。

答案 1 :(得分:1)

enter image description here可能是您在表格中使用的字段“检查”字段。它不会执行您的查询,因为它是预定义的约束。

 $qry2="INSERT INTO `c_n_discussion`
          (`TitleOfDes`, `TopicDec`, `DecImg`, `category`, 
           `visiblity`, `PostAs`, `check`) 
       VALUES ('$TitleOfDes','$TopicDec','$DesImg',
               '$category','$visiblity','$PostAs','$check')";

答案 2 :(得分:0)

<?php
if(isset($_POST["PostThisNow"])){
    $TitleOfDes = mysqli_real_escape_string($_POST['TitleOfDes']);
    $TopicDec = mysqli_real_escape_string($_POST['TopicDec']);
    $DesImg = mysqli_real_escape_string($_POST['DesImg']);
    $category = mysqli_real_escape_string($_POST['category']);
    $visiblity = mysqli_real_escape_string($_POST['visiblity']);
    $PostAs = mysqli_real_escape_string($_POST['PostAs']);
    $check = mysqli_real_escape_string($_POST['check']);



    $qry2="INSERT INTO c_n_discussion
              (TitleOfDes, TopicDec, DecImg, category, 
               visiblity, PostAs, check) 
           VALUES ('".$TitleOfDes."','".$TopicDec."','".$DesImg."',
                   '".$category."','".$visiblity."','".$PostAs."','".$check."')";

    if(mysqli_query($qry2)){
        echo "Records added successfully.";
    } else{
        echo "ERROR Could not able to execute $qry2. " . mysqli_error($con);
    }
}
?>