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/>";
}
}
长天一色2018-09-29 11:00:56
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.
神沐2018-09-28 15:51:42
$sql = "insert into stuAnswer values(".$m.",".$uid.",".$tihao[$i].",".$anser[$i].",".$bzhun[$i].",".$time_ks.")";
Try replacing the sql statement with this one
jin2018-09-28 10:47:03
You can print out the sql and execute it with phpmyadmin. Personally, I feel there is something wrong with the parameters in your values.
长天一色2018-09-28 09:50:00
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!