-1

i have this query where i want to insert all the variable in 3 separate table. but the alert says fail to submit but when i debug using var_dump() it seems like all the value successfully hold by the query. i already separate the query using ';' but nothing works.

here the query:

$query = "INSERT INTO tb_SCSP4114u(studID, attendance, commitment, decipline, rnr, socialization, manner, nvc, frequency, comment, totalscore)
        VALUES ('$sc', '$attendance', '$Commitment', '$Dicipline', '$rnr', '$Socialization', '$Manner', '$nvc', '$Frequency', '$comment1', '$tscore1');
        INSERT INTO tb_4124u(studID, pot, iop, ioo, tka, tpp, we, ec, bl, vs, o, c, comment, tscore)
        VALUES ('$sc', '$task', '$problem', '$obj', '$tka', '$tpp', '$work', '$eye', '$body', '$vs', '$Organization', '$Creativity', '$comment2', '$tscore2');
        INSERT INTO tb_4134u(studID, ons, ct, snf, cd, cr, pl, op, comment, tscore)
        VALUES ('$sc', '$ons', '$ct', '$lv', '$snf', '$cd', '$cr', '$Plagiarism', '$pw', '$comment3', '$tscore3');";

//var_dump($query);
if (mysqli_multi_query($con, $query)) 
{
    echo '<script> alert("Assessment Successfully Submitted\n\n");window.location="unicindex.php"</script>';
}
else 
{
    echo '<script> alert("Assessment Failed to submit\n\n");window.location="assessmentuc.php"</script>';
}

mysqli_close($con);

here is the debug result:

string(581) "INSERT INTO tb_SCSP4114u(studID, attendance, commitment, decipline, rnr, socialization, manner, nvc, frequency, comment, totalscore) VALUES ('A14CS0099', '5', '5', '5', '5', '5', '5', '5', '5', 'SDX', '40'); 
INSERT INTO tb_4124u(studID, pot, iop, ioo, tka, tpp, we, ec, bl, vs, o, c, comment, tscore) VALUES ('A14CS0099', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', 'dcsc', '55'); 
INSERT INTO tb_4134u(studID, ons, ct, snf, cd, cr, pl, op, comment, tscore) VALUES ('A14CS0099', '5', '5', '5', '5', '5', '5', '5', '5', 'dwce', '40');"
Barmar
  • 596,455
  • 48
  • 393
  • 495
  • 1
    When a query fails, use `mysqli_error()` to find out why. – Barmar May 21 '21 at 19:13
  • 1
    I strongly recommend against using `mysqli_multi_query()`. It rarely makes anything easier, and makes it harder to process the results. Just call `mysqli_query()` multiple times. That will also allow you to use prepared statements, which you should prefer. – Barmar May 21 '21 at 19:14
  • **DO NOT USE `mysqli_multi_query()`**. Each query needs to be executed separately using a prepared statement. – Dharman May 21 '21 at 21:06
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman May 21 '21 at 21:06
  • @Barmar i have tried what you have suggested, but only one table is successfully inserted the others have no change. the table that successfully updated is the tb_4124u. – Mica Pober May 22 '21 at 04:56
  • You must have done something wrong. There's no reason why only the 2nd query would work. – Barmar May 22 '21 at 17:48

0 Answers0