Please help, the database insertion operation failed.
长天一色
长天一色 2018-09-28 09:36:00
0
8
1792

The code is as follows:

$con = new mysqli($servername, $username, $password, $dbname);
if ($con->connect_error) {
die(" Database connection failed: " . $conn->connect_error);
}
echo "Database connection successful!";
for($i = 0 ; $i < 20 ; $i )
{
echo "Enter loop!<br/>";
$m = $i 1;
$sql = "insert into stuAnswer values('$m','$uid', '$tihao[$i]','$anser[$i]','$bzhun[$i]','$time_ks')";
$result = $con->query($sql) ;
if($result)
{
                  echo "Insertion successful!<br/>";
}
}



##Results of the:

qiuz.png

长天一色
长天一色

reply all(5)
长天一色

Thank you very much for your answers. I just found the crux of the problem. It is because the field names of the data table stuAnswer use Chinese names, which makes the data unable to be inserted. If you change it to English field names, you can insert it normally. Thanks again for everyone's guidance and enthusiasm.

雪霜

Is it a database primary key conflict

  • reply No primary key set
    长天一色 author 2018-09-29 10:33:05
神沐
$sql = "insert into stuAnswer values(".$m.",".$uid.",".$tihao[$i].",".$anser[$i].",".$bzhun[$i].",".$time_ks.")";

Try replacing the sql statement with this one

  • reply Thank you, I tried it, but it still doesn't work
    长天一色 author 2018-09-28 18:52:31
jin

You can print out the sql and execute it with phpmyadmin. Personally, I feel there is something wrong with the parameters in your values.

  • reply The sql statement can be executed under mysql. Moreover, after I added the echo statement to output the parameter data before $sql in the program just now, the variable data can be output. I really don’t understand why the insertion operation cannot be performed. Thank you very much for your enthusiasm!
    长天一色 author 2018-09-28 11:16:33
长天一色

It can be seen from the above execution results that the database connection is normal, but the insertion operation is not performed. I have read a lot of online information and cannot find the error in the code itself. I am a novice. Please give me some advice. Thank you!

  • reply Another point to add is that the order of fields in the data table is the same as the order of inserting values.
    长天一色 author 2018-09-28 09:54:12
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template