headmine Posted April 15, 2009 Share Posted April 15, 2009 I have a form page. Each of the input ID's are set as bq1 bq2 bq3 etc.... When the form is submitted I am trying to get this to work but I run into an error mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $uid = $_GET['ID']; $counter = 1; $frm = 1; while ( $frm <= 18 ) { "$bq" . $frm . " = $_POST[bq" . $frm . "]" $frm = $frm + 1; } while ( $counter <= 18 ) { mysql_query("UPDATE questions SET bq". $counter ." = '$bq". $counter ."' WHERE ID = 'uid'"); $counter = $counter + 1; } I get this error Parse error: syntax error, unexpected '"', expecting ']' in /PATH/TO/FILE/template/process/bqUpdate.php on line 9 Line 9 is "$bq" . $frm . " = $_POST[bq" . $frm . "]"; What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/154273-solved-help-with-mysql/ Share on other sites More sharing options...
Carth Posted April 15, 2009 Share Posted April 15, 2009 "$bq" . $frm . " = $_POST[bq" . $frm . "]" This line doesn't make sense. It's just a long string concatenation, and some of your PHP code is inside the string. I can't work out what that line is supposed to do, but if you explain it maybe I can tell you how it should be. As you can see from the syntax highlighting, the assignment is inside the string. Also it doesn't end in a semicolon. If you were planning on setting $bq18, $bq17 etc, and then accessing them, then that code won't work. It would have to use variable variables. What you have on the left of your assignment is just a string concatenation, not a variable to assign to. But that is a messy way of doing it, you'd be better with an array. Link to comment https://forums.phpfreaks.com/topic/154273-solved-help-with-mysql/#findComment-811049 Share on other sites More sharing options...
headmine Posted April 15, 2009 Author Share Posted April 15, 2009 Yea I am trying to get it to do this $frm = 1; while ($frm <= 18 ) { $bq . $frm = $_POST["bq" . $frm ]; $frm = $frm + 1; } The above should output $bq1 = $_POST[bq1]; $bq2 = $_POST[bq2]; etc Link to comment https://forums.phpfreaks.com/topic/154273-solved-help-with-mysql/#findComment-811054 Share on other sites More sharing options...
Carth Posted April 15, 2009 Share Posted April 15, 2009 OK then. You will have to change it like this: mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $uid = $_GET['ID']; $counter = 1; $frm = 1; while ( $frm <= 18 ) { ${"bq" . $frm} = $_POST["bq" . $frm ]; $frm = $frm + 1; } while ( $counter <= 18 ) { mysql_query("UPDATE questions SET bq". $counter ." = '" . ${"bq" . $counter} . "' WHERE ID = 'uid'"); $counter = $counter + 1; } Link to comment https://forums.phpfreaks.com/topic/154273-solved-help-with-mysql/#findComment-811060 Share on other sites More sharing options...
headmine Posted April 16, 2009 Author Share Posted April 16, 2009 I could cry... Thank you! Link to comment https://forums.phpfreaks.com/topic/154273-solved-help-with-mysql/#findComment-811071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.