Jump to content

Whats the error in this Insert Statement...???


genext.brite

Recommended Posts

Hii phpfreaks...

I'm running a simple mysql insert statement and getting a Parse Error.My code is :

 

<html>
<body>
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die ('Can not connect to :' .mysql_error());
}
   mysql_select_db("brite",$con);
   $sql="insert into subjects VALUES('$_POST['subname']','$_POST]['submarks']','$_POST['subgrade']','T')";
   mysql_close();
header('Location:subject.php');
<?> 

 

My help me someone ,I'm screwed trying to fight it.

Thanx in advance.

 

MOD EDIT: code tags added

Although I suspect there will be other problems, try these changes.

 

$sql="INSERT INTO subjects VALUES('{$_POST['subname']}', '{$_POST['submarks']}', '{$_POST['subgrade']}', 'T')";

 

AND

 

?> // NOT <?>

heyy...every1 ...I tried everything but still nothings working...

and @Pikachu 2000- sir i evn tried that syntax but no gain.

My exact error is - Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\My files\insert.php on line 10.

 

Plzz someone help me.I'm helpless!!!

Try this:

<html>
<body>
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die ('Can not connect to :' .mysql_error());
}
mysql_select_db("brite",$con);
   
   $sql="insert into subjects VALUES('{$_POST['subname']}','{$_POST['submarks']}','{$_POST['subgrade']}','T')";
   
   mysql_query($sql) or trigger_error( mysql_error() );
   mysql_close();
header('Location:subject.php');
exit();
?> 

 

You had an extra bracket (]) around one of your $_POST variables.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.