I have a list of values I am trying to enter into a mysql database with a dynamic number of rows. The variables are stored in $box1, $box2, and so on. I am trying to use UPDATE to put in the right value ($box1 in the first row selected, $box2 in the second row selected, and so on) in each consecutive row of the table. I’m not sure what code I have to type in the “while” loop to make this happen.
<?php
// Retrieve data from Query String
$box1 = $_GET['box1'];
$box2 = $_GET['box2'];
$box3 = $_GET['box3'];
$box4 = $_GET['box4'];
$box5 = $_GET['box5'];
$session = session_id();
//build query
$query = "SELECT * FROM sessionid WHERE sessionid='$session' ";
//Execute query
$qry_result = mysql_query($query) or die(mysql_error());
// Insert the right quantity in each row for each consecutive box
$i=1;
while($row = mysql_fetch_array($qry_result)){
mysql_query("UPDATE `sessionid` SET `qt`='$box' .$i . '' WHERE `sessionid`='$session' ");
$i++;
}
?>
I am now inputting the data from the url on the previous page into an array $box[1]. I keep getting an error saying: Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/c/a/s/cashme/html/buylooper/change-qt.php on line 13. Line 13 refers to the line that UPDATE query. Any tips?
//Retrieve data from Query String, input into array, and update table
$count = $_SESSION['id'];
for ($i=1; $i<$count; $i++){
$box[$i] = $_GET['box'. $i .''];
mysql_query("UPDATE `sessionid` SET `qt`='$box["'. $i .'"]' WHERE `sessionid`='$session' AND `id`='$i' ");
echo $box[$i];
}