I am trying to INSERT some data into a database. I can do this on one FIELD just not on multiple. It seems to be a simple syntax issue. The error I get is:
Parse error: syntax error, unexpected ',', expecting ']'
The error is on the INSERT line:
<?php
$con = mysql_connect("local","username","password");
if (!$con)
{die('Could not connect: ' . mysql_error());}
mysql_select_db("npsreviews", $con);
$sql="INSERT INTO burkett (DATE, STORE, 5STAR, 4STAR, 3STAR, 2STAR, 1STAR, TOTAL, NPS) VALUES ('$_POST[DATE]', '$_POST[STORE]', '$_POST[5STAR]', '$_POST[4STAR]', '$_POST[3STAR]', '$_POST[2STAR]', '$_POST[1STAR]', '$_POST[TOTAL]', '$_POST[NPS]')";
if (!mysql_query($sql,$con)){die('Error: ' . mysql_error());}
mysql_close($con)
?>
Thanks in advance, I cannot find the answer when looking for Multiple $POST.
First of all, you’re missing quotes around the array indices; It should be
$_POST["STORE"], not$_POST[STORE]. Secondly, you can’t index arrays this way with string interpolation. You’ll need to use{$...}syntax:Or concatenate the pieces of the string:
Either method will produce:
Note: I’ve answered your question as a simple syntax error, but this does not solve your real problem, which is rampant SQL injection vulnerability.