Jump to content

Syntax error - Parse error: syntax error, unexpected T_STRING, expecting ']' in


Recommended Posts

I have a pretty straightforward schedule page that should write values to a MySQL DB.  Here is the relevant code:

 

To put into the DB:

 

<?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/db.php");

$sql = "INSERT INTO jos_schedule (700_401, 700_402, 700_403, 700_404, 700_405, 700_406, 700_407, 700_408, 700_409, 700_410, 700_411, 700_412, 700_413, 700_414, 700_415, 700_416, 700_417, 700_418, 700_419, 700_420, 700_421,
730_401, 730_402, 730_403, 730_404, 730_405, 730_406, 730_407, 730_408, 730_409, 730_410, 730_411, 730_412, 730_413, 730_414, 730_415, 730_416, 730_417, 730_418, 730_419, 730_420, 730_421,
800_401, 800_402, 800_403, 800_404, 800_405, 800_406, 800_407, 800_408, 800_409, 800_410, 800_411, 800_412, 800_413, 800_414, 800_415, 800_416, 800_417, 800_418, 800_419, 800_420, 800_421,
830_401, 830_402, 830_403, 830_404, 830_405, 830_406, 830_407, 830_408, 830_409, 830_410, 830_411, 830_412, 830_413, 830_414, 830_415, 830_416, 830_417, 830_418, 830_419, 830_420, 830_421,
900_401, 900_402, 900_403, 900_404, 900_405, 900_406, 900_407, 900_408, 900_409, 900_410, 900_411, 900_412, 900_413, 900_414, 900_415, 900_416, 900_417, 900_418, 900_419, 900_420, 900_421,
930_401, 930_402, 930_403, 930_404, 930_405, 930_406, 930_407, 930_408, 930_409, 930_410, 930_411, 930_412, 930_413, 930_414, 930_415, 930_416, 930_417, 930_418, 930_419, 930_420, 930_421,
1000_401, 1000_402, 1000_403, 1000_404, 1000_405, 1000_406, 1000_407, 1000_408, 1000_409, 1000_410, 1000_411, 1000_412, 1000_413, 1000_414, 1000_415, 1000_416, 1000_417, 1000_418, 1000_419, 1000_420, 1000_421,
1030_401, 1030_402, 1030_403, 1030_404, 1030_405, 1030_406, 1030_407, 1030_408, 1030_409, 1030_410, 1030_411, 1030_412, 1030_413, 1030_414, 1030_415, 1030_416, 1030_417, 1030_418, 1030_419, 1030_420, 1030_421,
1100_401, 1100_402, 1100_403, 1100_404, 1100_405, 1100_406, 1100_407, 1100_408, 1100_409, 1100_410, 1100_411, 1100_412, 1100_413, 1100_414, 1100_415, 1100_416, 1100_417, 1100_418, 1100_419, 1100_420, 1100_421,
1130_401, 1130_402, 1130_403, 1130_404, 1130_405, 1130_406, 1130_407, 1130_408, 1130_409, 1130_410, 1130_411, 1130_412, 1130_413, 1130_414, 1130_415, 1130_416, 1130_417, 1130_418, 1130_419, 1130_420, 1130_421,
1200_401, 1200_402, 1200_403, 1200_404, 1200_405, 1200_406, 1200_407, 1200_408, 1200_409, 1200_410, 1200_411, 1200_412, 1200_413, 1200_414, 1200_415, 1200_416, 1200_417, 1200_418, 1200_419, 1200_420, 1200_421,
1230_401, 1230_402, 1230_403, 1230_404, 1230_405, 1230_406, 1230_407, 1230_408, 1230_409, 1230_410, 1230_411, 1230_412, 1230_413, 1230_414, 1230_415, 1230_416, 1230_417, 1230_418, 1230_419, 1230_420, 1230_421,
1300_401, 1300_402, 1300_403, 1300_404, 1300_405, 1300_406, 1300_407, 1300_408, 1300_409, 1300_410, 1300_411, 1300_412, 1300_413, 1300_414, 1300_415, 1300_416, 1300_417, 1300_418, 1300_419, 1300_420, 1300_421,
1330_401, 1330_402, 1330_403, 1330_404, 1330_405, 1330_406, 1330_407, 1330_408, 1330_409, 1330_410, 1130_411, 1330_412, 1330_413, 1330_414, 1330_415, 1330_416, 1330_417, 1330_418, 1330_419, 1330_420, 1330_421,
1400_401, 1400_402, 1400_403, 1400_404, 1400_405, 1400_406, 1400_407, 1400_408, 1400_409, 1400_410, 1400_411, 1400_412, 1400_413, 1400_414, 1400_415, 1400_416, 1400_417, 1400_418, 1400_419, 1400_420, 1400_421,
1430_401, 1430_402, 1430_403, 1430_404, 1430_405, 1430_406, 1430_407, 1430_408, 1430_409, 1430_410, 1430_411, 1430_412, 1430_413, 1430_414, 1430_415, 1430_416, 1430_417, 1430_418, 1430_419, 1430_420, 1430_421,
1500_401, 1500_402, 1500_403, 1500_404, 1500_405, 1500_406, 1500_407, 1500_408, 1500_409, 1500_410, 1500_411, 1500_412, 1500_413, 1500_414, 1500_415, 1500_416, 1500_417, 1500_418, 1500_419, 1500_420, 1500_421,
1530_401, 1530_402, 1530_403, 1530_404, 1530_405, 1530_406, 1530_407, 1530_408, 1530_409, 1530_410, 1530_411, 1530_412, 1530_413, 1530_414, 1530_415, 1530_416, 1530_417, 1530_418, 1530_419, 1530_420, 1530_421,
1600_401, 1600_402, 1600_403, 1600_404, 1600_405, 1600_406, 1600_407, 1600_408, 1600_409, 1600_410, 1600_411, 1600_412, 1600_413, 1600_414, 1600_415, 1600_416, 1600_417, 1600_418, 1600_419, 1600_420, 1600_421,
1630_401, 1630_402, 1630_403, 1630_404, 1630_405, 1630_406, 1630_407, 1630_408, 1630_409, 1630_410, 1630_411, 1630_412, 1630_413, 1630_414, 1630_415, 1630_416, 1630_417, 1630_418, 1630_419, 1630_420, 1630_421,
1700_401, 1700_402, 1700_403, 1700_404, 1700_405, 1700_406, 1700_407, 1700_408, 1700_409, 1700_410, 1700_411, 1700_412, 1700_413, 1700_414, 1700_415, 1700_416, 1700_417, 1700_418, 1700_419, 1700_420, 1700_421)

VALUES ('$_REQUEST[700_401]','$_REQUEST[700_402]','$_REQUEST[700_403]','$_REQUEST[700_404]','$_REQUEST[700_405]','$_REQUEST[700_406]','$_REQUEST[700_407]','$_REQUEST[700_408]','$_REQUEST[700_409]','$_REQUEST[700_410]',
'$_REQUEST[700_411]','$_REQUEST[700_412]','$_REQUEST[700_413]','$_REQUEST[700_414]','$_REQUEST[700_415]','$_REQUEST[700_416]','$_REQUEST[700_417]','$_REQUEST[700_418]','$_REQUEST[700_419]','$_REQUEST[700_420]','$_REQUEST[700_421]',
'$_REQUEST[730_401]','$_REQUEST[730_402]','$_REQUEST[730_403]','$_REQUEST[730_404]','$_REQUEST[730_405]','$_REQUEST[730_406]','$_REQUEST[730_407]','$_REQUEST[730_408]','$_REQUEST[730_409]','$_REQUEST[730_410]',
'$_REQUEST[730_411]','$_REQUEST[730_412]','$_REQUEST[730_413]','$_REQUEST[730_414]','$_REQUEST[730_415]','$_REQUEST[730_416]','$_REQUEST[730_417]','$_REQUEST[730_418]','$_REQUEST[730_419]','$_REQUEST[730_420]','$_REQUEST[730_421]',
'$_REQUEST[800_401]','$_REQUEST[800_402]','$_REQUEST[800_403]','$_REQUEST[800_404]','$_REQUEST[800_405]','$_REQUEST[800_406]','$_REQUEST[800_407]','$_REQUEST[800_408]','$_REQUEST[800_409]','$_REQUEST[800_410]',
'$_REQUEST[800_411]','$_REQUEST[800_412]','$_REQUEST[800_413]','$_REQUEST[800_414]','$_REQUEST[800_415]','$_REQUEST[800_416]','$_REQUEST[800_417]','$_REQUEST[800_418]','$_REQUEST[800_419]','$_REQUEST[800_420]','$_REQUEST[800_421]',
'$_REQUEST[830_401]','$_REQUEST[830_402]','$_REQUEST[830_403]','$_REQUEST[830_404]','$_REQUEST[830_405]','$_REQUEST[830_406]','$_REQUEST[830_407]','$_REQUEST[830_408]','$_REQUEST[830_409]','$_REQUEST[830_410]',
'$_REQUEST[830_411]','$_REQUEST[830_412]','$_REQUEST[830_413]','$_REQUEST[830_414]','$_REQUEST[830_415]','$_REQUEST[830_416]','$_REQUEST[830_417]','$_REQUEST[830_418]','$_REQUEST[830_419]','$_REQUEST[830_420]','$_REQUEST[830_421]',
'$_REQUEST[900_401]','$_REQUEST[900_402]','$_REQUEST[900_403]','$_REQUEST[900_404]','$_REQUEST[900_405]','$_REQUEST[900_406]','$_REQUEST[900_407]','$_REQUEST[900_408]','$_REQUEST[900_409]','$_REQUEST[900_410]',
'$_REQUEST[900_411]','$_REQUEST[900_412]','$_REQUEST[900_413]','$_REQUEST[900_414]','$_REQUEST[900_415]','$_REQUEST[900_416]','$_REQUEST[900_417]','$_REQUEST[900_418]','$_REQUEST[900_419]','$_REQUEST[900_420]','$_REQUEST[900_421]',
'$_REQUEST[930_401]','$_REQUEST[930_402]','$_REQUEST[930_403]','$_REQUEST[930_404]','$_REQUEST[930_405]','$_REQUEST[930_406]','$_REQUEST[930_407]','$_REQUEST[930_408]','$_REQUEST[930_409]','$_REQUEST[930_410]',
'$_REQUEST[930_411]','$_REQUEST[930_412]','$_REQUEST[930_413]','$_REQUEST[930_414]','$_REQUEST[930_415]','$_REQUEST[930_416]','$_REQUEST[930_417]','$_REQUEST[930_418]','$_REQUEST[930_419]','$_REQUEST[930_420]','$_REQUEST[930_421]',
'$_REQUEST[1000_401]','$_REQUEST[1000_402]','$_REQUEST[1000_403]','$_REQUEST[1000_404]','$_REQUEST[1000_405]','$_REQUEST[1000_406]','$_REQUEST[1000_407]','$_REQUEST[1000_408]','$_REQUEST[1000_409]','$_REQUEST[1000_410]',
'$_REQUEST[1000_411]','$_REQUEST[1000_412]','$_REQUEST[1000_413]','$_REQUEST[1000_414]','$_REQUEST[1000_415]','$_REQUEST[1000_416]','$_REQUEST[1000_417]','$_REQUEST[1000_418]','$_REQUEST[1000_419]','$_REQUEST[1000_420]','$_REQUEST[1000_421]',
'$_REQUEST[1030_401]','$_REQUEST[1030_402]','$_REQUEST[1030_403]','$_REQUEST[1030_404]','$_REQUEST[1030_405]','$_REQUEST[1030_406]','$_REQUEST[1030_407]','$_REQUEST[1030_408]','$_REQUEST[1030_409]','$_REQUEST[1030_410]',
'$_REQUEST[1030_411]','$_REQUEST[1030_412]','$_REQUEST[1030_413]','$_REQUEST[1030_414]','$_REQUEST[1030_415]','$_REQUEST[1030_416]','$_REQUEST[1030_417]','$_REQUEST[1030_418]','$_REQUEST[1030_419]','$_REQUEST[1030_420]','$_REQUEST[1030_421]',
'$_REQUEST[1100_401]','$_REQUEST[1100_402]','$_REQUEST[1100_403]','$_REQUEST[1100_404]','$_REQUEST[1100_405]','$_REQUEST[1100_406]','$_REQUEST[1100_407]','$_REQUEST[1100_408]','$_REQUEST[1100_409]','$_REQUEST[1100_410]',
'$_REQUEST[1100_411]','$_REQUEST[1100_412]','$_REQUEST[1100_413]','$_REQUEST[1100_414]','$_REQUEST[1100_415]','$_REQUEST[1100_416]','$_REQUEST[1100_417]','$_REQUEST[1100_418]','$_REQUEST[1100_419]','$_REQUEST[1100_420]','$_REQUEST[1100_421]',
'$_REQUEST[1130_401]','$_REQUEST[1130_402]','$_REQUEST[1130_403]','$_REQUEST[1130_404]','$_REQUEST[1130_405]','$_REQUEST[1130_406]','$_REQUEST[1130_407]','$_REQUEST[1130_408]','$_REQUEST[1130_409]','$_REQUEST[1130_410]',
'$_REQUEST[1130_411]','$_REQUEST[1130_412]','$_REQUEST[1130_413]','$_REQUEST[1130_414]','$_REQUEST[1130_415]','$_REQUEST[1130_416]','$_REQUEST[1130_417]','$_REQUEST[1130_418]','$_REQUEST[1130_419]','$_REQUEST[1130_420]','$_REQUEST[1130_421]',
'$_REQUEST[1200_401]','$_REQUEST[1200_402]','$_REQUEST[1200_403]','$_REQUEST[1200_404]','$_REQUEST[1200_405]','$_REQUEST[1200_406]','$_REQUEST[1200_407]','$_REQUEST[1200_408]','$_REQUEST[1200_409]','$_REQUEST[1200_410]',
'$_REQUEST[1200_411]','$_REQUEST[1200_412]','$_REQUEST[1200_413]','$_REQUEST[1200_414]','$_REQUEST[1200_415]','$_REQUEST[1200_416]','$_REQUEST[1200_417]','$_REQUEST[1200_418]','$_REQUEST[1200_419]','$_REQUEST[1200_420]','$_REQUEST[1200_421]',
'$_REQUEST[1230_401]','$_REQUEST[1230_402]','$_REQUEST[1230_403]','$_REQUEST[1230_404]','$_REQUEST[1230_405]','$_REQUEST[1230_406]','$_REQUEST[1230_407]','$_REQUEST[1230_408]','$_REQUEST[1230_409]','$_REQUEST[1230_410]',
'$_REQUEST[1230_411]','$_REQUEST[1230_412]','$_REQUEST[1230_413]','$_REQUEST[1230_414]','$_REQUEST[1230_415]','$_REQUEST[1230_416]','$_REQUEST[1230_417]','$_REQUEST[1230_418]','$_REQUEST[1230_419]','$_REQUEST[1230_420]','$_REQUEST[1230_421]',
'$_REQUEST[1300_401]','$_REQUEST[1300_402]','$_REQUEST[1300_403]','$_REQUEST[1300_404]','$_REQUEST[1300_405]','$_REQUEST[1300_406]','$_REQUEST[1300_407]','$_REQUEST[1300_408]','$_REQUEST[1300_409]','$_REQUEST[1300_410]',
'$_REQUEST[1300_411]','$_REQUEST[1300_412]','$_REQUEST[1300_413]','$_REQUEST[1300_414]','$_REQUEST[1300_415]','$_REQUEST[1300_416]','$_REQUEST[1300_417]','$_REQUEST[1300_418]','$_REQUEST[1300_419]','$_REQUEST[1300_420]','$_REQUEST[1300_421]',
'$_REQUEST[1330_401]','$_REQUEST[1330_402]','$_REQUEST[1330_403]','$_REQUEST[1330_404]','$_REQUEST[1330_405]','$_REQUEST[1330_406]','$_REQUEST[1330_407]','$_REQUEST[1330_408]','$_REQUEST[1330_409]','$_REQUEST[1330_410]',
'$_REQUEST[1330_411]','$_REQUEST[1330_412]','$_REQUEST[1330_413]','$_REQUEST[1330_414]','$_REQUEST[1330_415]','$_REQUEST[1330_416]','$_REQUEST[1330_417]','$_REQUEST[1330_418]','$_REQUEST[1330_419]','$_REQUEST[1330_420]','$_REQUEST[1330_421]',
'$_REQUEST[1400_401]','$_REQUEST[1400_402]','$_REQUEST[1400_403]','$_REQUEST[1400_404]','$_REQUEST[1400_405]','$_REQUEST[1400_406]','$_REQUEST[1400_407]','$_REQUEST[1400_408]','$_REQUEST[1400_409]','$_REQUEST[1400_410]',
'$_REQUEST[1400_411]','$_REQUEST[1400_412]','$_REQUEST[1400_413]','$_REQUEST[1400_414]','$_REQUEST[1400_415]','$_REQUEST[1400_416]','$_REQUEST[1400_417]','$_REQUEST[1400_418]','$_REQUEST[1400_419]','$_REQUEST[1400_420]','$_REQUEST[1400_421]',
'$_REQUEST[1430_401]','$_REQUEST[1430_402]','$_REQUEST[1430_403]','$_REQUEST[1430_404]','$_REQUEST[1430_405]','$_REQUEST[1430_406]','$_REQUEST[1430_407]','$_REQUEST[1430_408]','$_REQUEST[1430_409]','$_REQUEST[1430_410]',
'$_REQUEST[1430_411]','$_REQUEST[1430_412]','$_REQUEST[1430_413]','$_REQUEST[1430_414]','$_REQUEST[1430_415]','$_REQUEST[1430_416]','$_REQUEST[1430_417]','$_REQUEST[1430_418]','$_REQUEST[1430_419]','$_REQUEST[1430_420]','$_REQUEST[1430_421]',
'$_REQUEST[1500_401]','$_REQUEST[1500_402]','$_REQUEST[1500_403]','$_REQUEST[1500_404]','$_REQUEST[1500_405]','$_REQUEST[1500_406]','$_REQUEST[1500_407]','$_REQUEST[1500_408]','$_REQUEST[1500_409]','$_REQUEST[1500_410]',
'$_REQUEST[1500_411]','$_REQUEST[1500_412]','$_REQUEST[1500_413]','$_REQUEST[1500_414]','$_REQUEST[1500_415]','$_REQUEST[1500_416]','$_REQUEST[1500_417]','$_REQUEST[1500_418]','$_REQUEST[1500_419]','$_REQUEST[1500_420]','$_REQUEST[1500_421]',
'$_REQUEST[1530_401]','$_REQUEST[1530_402]','$_REQUEST[1530_403]','$_REQUEST[1530_404]','$_REQUEST[1530_405]','$_REQUEST[1530_406]','$_REQUEST[1530_407]','$_REQUEST[1530_408]','$_REQUEST[1530_409]','$_REQUEST[1530_410]',
'$_REQUEST[1530_411]','$_REQUEST[1530_412]','$_REQUEST[1530_413]','$_REQUEST[1530_414]','$_REQUEST[1530_415]','$_REQUEST[1530_416]','$_REQUEST[1530_417]','$_REQUEST[1530_418]','$_REQUEST[1530_419]','$_REQUEST[1530_420]','$_REQUEST[1530_421]',
'$_REQUEST[1600_401]','$_REQUEST[1600_402]','$_REQUEST[1600_403]','$_REQUEST[1600_404]','$_REQUEST[1600_405]','$_REQUEST[1600_406]','$_REQUEST[1600_407]','$_REQUEST[1600_408]','$_REQUEST[1600_409]','$_REQUEST[1600_410]',
'$_REQUEST[1600_411]','$_REQUEST[1600_412]','$_REQUEST[1600_413]','$_REQUEST[1600_414]','$_REQUEST[1600_415]','$_REQUEST[1600_416]','$_REQUEST[1600_417]','$_REQUEST[1600_418]','$_REQUEST[1600_419]','$_REQUEST[1600_420]','$_REQUEST[1600_421]',
'$_REQUEST[1630_401]','$_REQUEST[1630_402]','$_REQUEST[1630_403]','$_REQUEST[1630_404]','$_REQUEST[1630_405]','$_REQUEST[1630_406]','$_REQUEST[1630_407]','$_REQUEST[1630_408]','$_REQUEST[1630_409]','$_REQUEST[1630_410]',
'$_REQUEST[1630_411]','$_REQUEST[1630_412]','$_REQUEST[1630_413]','$_REQUEST[1630_414]','$_REQUEST[1630_415]','$_REQUEST[1630_416]','$_REQUEST[1630_417]','$_REQUEST[1630_418]','$_REQUEST[1630_419]','$_REQUEST[1630_420]','$_REQUEST[1630_421]',
'$_REQUEST[1700_401]','$_REQUEST[1700_402]','$_REQUEST[1700_403]','$_REQUEST[1700_404]','$_REQUEST[1700_405]','$_REQUEST[1700_406]','$_REQUEST[1700_407]','$_REQUEST[1700_408]','$_REQUEST[1700_409]','$_REQUEST[1700_410]',
'$_REQUEST[1700_411]','$_REQUEST[1700_412]','$_REQUEST[1700_413]','$_REQUEST[1700_414]','$_REQUEST[1700_415]','$_REQUEST[1700_416]','$_REQUEST[1700_417]','$_REQUEST[1700_418]','$_REQUEST[1700_419]','$_REQUEST[1700_420]','$_REQUEST[1700_421]')";

 

 

But on submit from the feeding page, I get "Parse error: syntax error, unexpected T_STRING, expecting ']' in C:\xampp\htdocs\sched_board\schedboard4_posted.php on line 44

 

Line 44 is the line starting with VALUES (

 

This has to be a syntax error, but I cannot see anything (missing ' or anything like that)

 

I include the 2 php files as well.

 

Thanks in Advance

 

[attachment deleted by admin]

Also, since it looks like the form fields are the same as the db columns then you might do it like this. Much shorter and easier and it uses mysql_real_escape_string() which you REALLY need to use.  If you named all of your form fields that contain the data to insert like this:

 

name="data[700_401]"

 

Then this would do what you are doing:

 

$cols = "`" . implode("`,`", array_keys($_POST['data'])) . "`";
$data = "'" . implode("','", array_map("mysql_real_escape_string", $_POST['data'])) . "'";
$sql  = "INSERT INTO jos_schedule ($cols) VALUES ($vals)";

Shawn - thanks for both replies.

 

I am a PHP toddler, so the second reply kind of smokes my braincells.

 

Do you mean I should do this:

name="data[700_401]"

name="data[700_402]"

name="data[700_403]"

 

etc.

 

and then use

$cols = "`" . implode("`,`", array_keys($_POST['data'])) . "`";$data = "'" . implode("','", array_map("mysql_real_escape_string", $_POST['data'])) . "'";$sql  = "INSERT INTO jos_schedule ($cols) VALUES ($vals)";

 

?

 

Thanks!

Joe

 

It would be easier and you could make it into a function so you could reuse it for other forms:

 

function insert_data($table, $data) {
   $cols = "`" . implode("`,`", array_keys($data)) . "`";
   $data = "'" . implode("','", array_map("mysql_real_escape_string", $data)) . "'";
   $sql  = "INSERT INTO $table ($cols) VALUES ($vals)";
}

insert_data('jos_schedule', $_POST['data']);

 

a typo?

  $data = "'" . implode("','", array_map("mysql_real_escape_string", $data)) . "'";

  $sql  = "INSERT INTO $table ($cols) VALUES ($vals)";

Why yes it is.  Should be:

 

 $vals = "'" . implode("','", array_map("mysql_real_escape_string", $data)) . "'";

 

 

I changed the form fields as you suggested, and then in the posted page I used the code: The posted page has this code (these are lines 20-37):

<?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/db.php");


   $cols = "'" . implode("','", array_keys($_POST['data'])) . "'";
   $vals = "'" . implode("','", array_map("mysql_real_escape_string", $data)) . "'";
   $sql  = "INSERT INTO jos_schedule ($cols) VALUES ($vals)";


if (!mysql_query($sql,$db))
    {
    die('Error: '.mysql_error());
    }
mysql_close($db);

print "<H2>Schedule Update has been successfully submitted.</H2>";
print "<br>Thank you.<br>";

?>

 

but now I get these errors:

 

Warning: array_map() [function.array-map]: Argument #2 should be an array in C:\xampp\htdocs\sched_board\schedboard_new_posted.php on line 24

 

Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\sched_board\schedboard_new_posted.php on line 24

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 ''700_401','730_401','800_401','830_401','900_401','930_401','1000_401','1030_401' at line 1

Somehow made another typo in my function post, but it was correct in the original:

 

$vals = "'" . implode("','", array_map("mysql_real_escape_string", $_POST['data'])) . "'";

OK, getting closer.  Now the issue seems to be in my 'sending' page.

 

I get one error now:

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 ''700_401','730_401','800_401','830_401','900_401','930_401','1000_401','1030_401' at line 1

 

Here is that piece of code from that page:

<tr>
<td>401</td>
<td><select name="data[700_401]" SIZE="1">
<?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/db.php");

$result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[730_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[800_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[830_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[900_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[930_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[1000_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>
<td><select name="data[1030_401]" SIZE="1">
<?php  $result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort",$db);
    while ($myrow = mysql_fetch_array($result))
   {
$fieldvalue=$myrow["fieldvalue"];
echo "<option value = ".$fieldvalue.">".$fieldvalue."</option>";
   }
echo "</select></td>";
?>

 

I also am attaching both php files.

 

Thanks,

 

Joe

 

[attachment deleted by admin]

My code:

$cols = "`" . implode("`,`", array_keys($data)) . "`";

 

Your code:

$cols = "'" . implode("','", array_keys($_POST['data'])) . "'";

 

You need to use backticks ` and not single quotes ' to surround coulmn names.

 

Also, you have way too much code and you repeat the same query multiple times in the form code.  I'll post a suggestion in a minute.

OK, so run the query once and build an options string of all the options to use in your selects (just an example):

 

<?php
//do the query once
$result = mysql_query("SELECT fieldvalue FROM jos_sched_values order by sort", $db);

//loop once and build the options in a string so you can reuse it
$options = '';
while ($myrow = mysql_fetch_assoc($result)) {
    $options .= '<option value="'.$myrow["fieldvalue"].'">'.$myrow["fieldvalue"].'</option>';
}
//do all of your selects and just echo the options
?>
<select name="data[700_401]" SIZE="1"><?php echo $options; ?></select>

<select name="data[730_401]" SIZE="1"><?php echo $options; ?></select>

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.