Hey Experts,
Please Help me.. i am facing this error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\tf\process.php on line 22

for($b=1;$b<$_POST['studentcount'];$b++)
{
$c='sname' . $b;
$ql="INSERT INTO stud (name) VALUES ('$_POST['sname1'])"; /*line 22*/
mysql_query($ql);
}

Please do checkwhats wrong with this,
Regards,
Vigas Deep

Recommended Answers

All 4 Replies

for($b=1;$b<$_POST['studentcount'];$b++)
{
$c='sname' . $b;
$ql="INSERT INTO stud (name) VALUES ('$_POST['sname1'])"; /*line 22*/
mysql_query($ql);
}

Well, for one thing you're missing a quote after the $_POST array statement. For another, arrays don't automatically parse in a string.
So this:

echo "$myArray['myIndex']";

Would give you an error.
Try this:

$ql="INSERT INTO stud (name) VALUES ('{$_POST['name1']}')";

Inserting the brackets {} around the array tells the compiler to parse it first.

It is not good to use $_POST value directly in the sql query. at least need prevent some sql injections...
But if you really need it as is then you lost one ' between brackets ])
or use like this
$ql="INSERT INTO stud (name) VALUES ('".$_POST".')";

Best
Vitana

http://vitana-group.com/

Good point, I didn't think about the SQL injection weakness there. You could solve both problems by doing something like this:

$name = mysql_real_escape_string($_POST['sname1']);

$ql="INSERT INTO stud (name) VALUES ('$name')";

i also agree. you should put your request/post value into any variable and then use it. dont put it directly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.