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/>";
}
}
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
Try replacing the sql statement with this one
You can print out the sql and execute it with phpmyadmin. Personally, I feel there is something wrong with the parameters in your values.
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!