Jump to content

[SOLVED] Help with MySql


headmine

Recommended Posts

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

"$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.

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.