Jump to content

Archived

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

DanielStead

Can anyone tell me why this query is not working?

Recommended Posts

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$sql_1 = "INSERT INTO SourceDocument (MapRef,Township,Parish,Dimensions,DateOfMap,Surveyor)

VALUES('$_SESSION['MapRef']','$_SESSION['Township']','$_SESSION['Parish']'

,'$_SESSION['SizeCM']','$_POST['DateofMap']','$_POST['Surveyor']')";

 

sorry its probably something really easy but this query works fine

 

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]

$sql_1 = "INSERT INTO SourceDocument (MapRef,Township,Parish,Dimensions,DateOfMap,Surveyor)";

 

so there seems to be something worng with my quieries but i cant spot it.

 

Share this post


Link to post
Share on other sites

Sure.. I think you have quoting issues for your column values; the second query just uses the default column values, so there's no problem.

 

'$_SESSION['MapRef']'

 

That's hard to parse -- where does the field value start & end? I see 4 single quotes -- and MySQL doesn't like them very much anyway. I would have broken out each hash key to keep from having to escape your quotes, which just looks horrible:

 

'".$_SESSION['MapRef']."'

 

Hope that helps.

Share this post


Link to post
Share on other sites

[!--quoteo(post=336976:date=Jan 16 2006, 12:09 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 16 2006, 12:09 PM) 336976[/snapback][/div][div class=\'quotemain\'][!--quotec--]

Sure.. I think you have quoting issues for your column values; the second query just uses the default column values, so there's no problem.

 

'".$_SESSION['MapRef']."'

 

Hope that helps.

 

the quoting issues is definitely the problem, and there are several ways to fix it... just choose whichever is easiest for you to view:

 

// this way
VALUES('{$_SESSION['MapRef']}','{$_SESSION['Township']}','{$_SESSION['Parish']}'
,'{$_SESSION['SizeCM']}','{$_POST['DateofMap']}','{$_POST['Surveyor']}')";

// or this way
VALUES('$_SESSION[MapRef]','$_SESSION[Township]','$_SESSION[Parish]'
,'$_SESSION[SizeCM]','$_POST[DateofMap]','$_POST[Surveyor]')";

// or the way mentioned above

Share this post


Link to post
Share on other sites

Just don't use the bareword hash keys (shudder) -- go with the explicit quoting, or the curlies.

Share this post


Link to post
Share on other sites

×

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.