Jump to content


Photo

problem w/ php mysql syntax


  • Please log in to reply
8 replies to this topic

#1 croakingtoad

croakingtoad
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationUSA

Posted 25 May 2006 - 06:38 PM

here's what I have-
$query = mysql_query("SELECT * FROM $table WHERE mls = $MLS") or die(mysql_error());

I'm getting the error-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE mls = 701555' at line 1

What am I doing wrong?

#2 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 25 May 2006 - 06:50 PM

$query = mysql_query("SELECT * FROM $table WHERE mls = [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--] $MLS [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--] ") or die(mysql_error());

#3 croakingtoad

croakingtoad
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationUSA

Posted 25 May 2006 - 06:55 PM

I changed mine to match your suggestion but I still get the error--
$query = mysql_query("SELECT * FROM $table WHERE mls = '$MLS'") or die(mysql_error());

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE mls = '701555'' at line 1


#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 May 2006 - 06:58 PM

you sure mls is an integer type data type?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 croakingtoad

croakingtoad
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationUSA

Posted 25 May 2006 - 07:10 PM

that's what it was, i had it as varchar

#6 croakingtoad

croakingtoad
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationUSA

Posted 26 May 2006 - 03:42 PM

Okay, maybe not... I changed it in the DB from varchar to int and empties the DB then ran the script to put data back into it and I am still getting that error. Any other ideas?


#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 May 2006 - 03:51 PM

$query = mysql_query("SELECT * FROM $table WHERE mls = '$MLS'") or die("Error: ". mysql_error(). " with query ". $query);
That way you can see the actual query being used that results in the error.
Legend has it that reading the manual never killed anyone.
My site

#8 croakingtoad

croakingtoad
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationUSA

Posted 26 May 2006 - 04:19 PM

That didn't give much more info--

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE mls = '701555'' at line 1 with query

What's strange is when I type the query into SQLyog--

SELECT * FROM flex_residential WHERE mls = 701555

it returns the correct result...

I'm such an idiot, nevermind. I wasn't passing a required variable to the url to satisfy a switch I had right above this code that gives the value of $table.

Sorry for my Friday dumbness!

#9 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 26 May 2006 - 04:59 PM

Try to add the `` quotes around the table name and the mls like this
$query = mysql_query("SELECT * FROM `$table` WHERE `mls` = '$MLS'") or die("Error: ". mysql_error(). " with query ". $query);

Sometimes this does the trick for me

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users