Building a dynamic $_POST statement
ingHey guys.
I am wonder the correct syntax for using a $_POST statement in a while loop.
I hav开发者_如何学Pythone written this.
$result_i = $_POST['result_i'];
while ($result_i > 0){
//Get Post Values
$driver = $_POST['driver_update_".$result_i."'];
$BookingID = $_POST['ID_".$result_i."'];
$Task_No_update = $_POST['Task_No_update_".$result_i."'];
//SQL
$driver_update = mysql_query("UPDATE booking SET driver = '$driver', TaskNo= '$Task_No_update' WHERE BookingID = '$BookingID' " );
}
The problem I have is:
$_POST['driver_update_".$result_i."'];
Is it possible to write $_POSTS statements in this way.
Cheers.
The problem is you cannot interpolate variables in single-quoted strings.
Try concatenation instead
$_POST['driver_update_' . $result_i]
or use double-quotes and variable enclosures
$_POST["driver_update_{$result_i}"]
See http://www.php.net/manual/en/language.types.string.php
Also, that looks like an infinite loop as $result_i
never changes.
You don't need to wrap everything in quotes here
$driver = $_POST["driver_update_" . $result_i];
$BookingID = $_POST["ID_" . $result_i];
$Task_No_update = $_POST["Task_No_update_" . $result_i];
精彩评论