Jump to content

Recommended Posts

For the life of me I cannot figure out where the error in this code is:

 

$q_test3 = mysql_query("select * from ans2 where test_id='$id' order by id asc") or die(mysql_error());
while ($g_test3 = mysql_fetch_array($q_test3))$num_ans = $num_ans+1;
{
$var = "q2a".$num_ans;
$var2 = "corans".$num_ans;
$ans = $_POST[$var];
$chk = $_POST[$var2];
$id2 = $g_test3['id'];
mysql_query("update ans2 set ans='$ans', corans='$chk' where id=$id2")or die(mysql_error());
}

 

I stripped the code down to only the parts that could potentially be affecting the error.  I am getting the following error:

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 ')' at line 1

I have checked all the needed variables, and $ans and $chk both are producing results from the previous form (The num_ans is a number always going up by one which is needed for this script).  The $ans field comes from a text box and $chk is a check box.  My test is running 4 fields right now, and the first entry updates without a problem but the next one produces this error.  Any ideas?

 

Edit:  I noticed that it is updating the first entry but it is not producing a confirmation after the update that is needed.  IE The tables are all updated but the error is coming from the first entry.

Link to comment
https://forums.phpfreaks.com/topic/204575-stupid-error/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.