Jump to content


Photo

Can anyone tell me why this query is not working?


  • Please log in to reply
3 replies to this topic

#1 DanielStead

DanielStead
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 16 January 2006 - 12:50 PM

[!--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']')"; [/quote]

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)";
[/quote]

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


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 January 2006 - 05:09 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 16 January 2006 - 06:03 PM

[!--quoteo(post=336976:date=Jan 16 2006, 12:09 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 16 2006, 12:09 PM) View Post[/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.
[/quote]

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

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 January 2006 - 08:51 PM

Just don't use the bareword hash keys (shudder) -- go with the explicit quoting, or the curlies.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users