Help with SQL syntax error message
Posted: Mon Oct 05, 2009 12:06 pm
I can't figure out what the syntax error is in this code. This is the message I get:
This is the code I'm using:
If I comment out line nine ( $resInsertAdv = mysqli_query($mysqli, $sqlInsertAdv) or die(mysqli_error($mysqli));), the code runs fine. In particular, line 8 correctly echos the relevant values. Also, the initial $sqlDeleteAdvLink seems to work fine.
As soon as I try to run it with line 9, however, I get the error message.
Can anyone see what's going wrong?
Thanks.
Code: Select all
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['fac_id'])' at line 1Code: Select all
$sqlDeleteAdvLink = "DELETE FROM tblStudFac WHERE stud_id = $stud_id";
$resDeleteAdvLink = mysqli_query($mysqli, $sqlDeleteAdvLink) or die(mysqli_error($mysqli));
$n = count($fac);
for($i=0;$i < $n; $i++) {
//echo $fac[$i]['fac_id'].$fac[$i]['fac_name'].$fac[$i]['advStatus']."<br />";
if($fac[$i]['advStatus']=="True") {
$sqlInsertAdv = "INSERT INTO tblStudFac VALUES ($stud_id, $fac[$i]['fac_id'])";
echo $fac[$i]['fac_id'].$fac[$i]['fac_name'].$fac[$i]['advStatus']."<br />";
$resInsertAdv = mysqli_query($mysqli, $sqlInsertAdv) or die(mysqli_error($mysqli));
mysqli_free_result($resInsertAdv);
}
}
As soon as I try to run it with line 9, however, I get the error message.
Can anyone see what's going wrong?
Thanks.