stephtort Posted December 5, 2006 Share Posted December 5, 2006 Hi there. I'm trying to adapt an existing php/mysql insert/update form with new fields and information, and I'm running into an error. I am ok with PHP, but definitely not well-versed so I'm having trouble narrowing down the problem. Can someone help by taking a look at the code and giving me advice on what to fix?The error I'm getting is this:[code]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 id=''' at line 1[/code]It looks like there is an extra ' somewhere in the code, but I cannot find it.I've made a .zip file with all necessary files that can be reviewed here (including the table structure):http://www.schteff.com/phphelp.zipThanks in advance for any help! Quote Link to comment Share on other sites More sharing options...
jsladek Posted December 5, 2006 Share Posted December 5, 2006 WOW!, that is some crazy stuff. The first thing to do is to print out the $sql right before this line[code]mysql_query($sql) or print('<b>Error:</b>'.mysql_error());[/code]there are two of these one around line 49 and the other around 79.This will show you what the sql actually looks like and that will help you narrow it down.-John Quote Link to comment Share on other sites More sharing options...
stephtort Posted December 5, 2006 Author Share Posted December 5, 2006 The error is listed (printed) above.... Quote Link to comment Share on other sites More sharing options...
Orio Posted December 5, 2006 Share Posted December 5, 2006 Can you just post the script, or at least the relevant part?Orio. Quote Link to comment Share on other sites More sharing options...
jsladek Posted December 5, 2006 Share Posted December 5, 2006 I saw the error, now print out the SQL and post that [code]print("sql: $sql")[/code]Help us help you..-John Quote Link to comment Share on other sites More sharing options...
stephtort Posted December 10, 2006 Author Share Posted December 10, 2006 sorry - got sent out of town for a few days for work.ok - I added the print command, and also drastically reduced the update form into smaller sections so I could see if a specific field was giving me the error.Here is the print result:[code]sql: update contestinfo set sponsor='test', coordinator='test', coordaddress='test', coordcity='test', coordstate='test', coordzip='test', coordphone1='test', coordphone2='test', coordemail='test', emergency='test', emergencyphone='test', addl1='test', addlemail1='test', addl2='test', addlemail2='test', addl3='test'addlemail3='test', where id=''[/code]In the actual insert.php file, here is the array:[code] 'host' => Array( 'contestinfo' => Array( 'sponsor','coordinator','coordaddress','coordcity','coordstate','coordzip','coordphone1','coordphone2','coordemail','emergency','emergencyphone','addl1','addlemail1','addl2','addlemail2','addl3','addlemail3', ), ),[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2006 Share Posted December 10, 2006 Look at your sql statement, in particular [i], where id=''[/i]There should be no , before WHERE and id needs to have some value.Post your code!!! And please, do as every other programmer does and make your sql keywords capitol letters for easy reading. eg;[code]INSERT INTO tblname SET val1='value1' WHERE id=4;[/code] Quote Link to comment Share on other sites More sharing options...
stephtort Posted December 10, 2006 Author Share Posted December 10, 2006 [quote]And please, do as every other programmer does... [/quote]Not the original author of the code, sorry.. :-[ I adjusted the capitalization.No matter which fields are the last two in the array, I still get the error.[code]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 'addlemail3='test', WHERE id=''' at line 1[/code][code]sql: UPDATE contestinfo SET sponsor='test', coordinator='test', coordaddress='test', coordcity='test', coordstate='test', coordzip='test', coordphone1='test', coordphone2='test', coordemail='test', emergency='test', emergencyphone='test', addl1='test', addlemail1='test', addl2='test', addlemail2='test', addl3='test'addlemail3='test', WHERE id=''[/code] Quote Link to comment Share on other sites More sharing options...
stephtort Posted December 10, 2006 Author Share Posted December 10, 2006 removed the actual code ... this forum is really not being helpful.[quote]Your kidding aren't ya? The relevent code will be sufficient, no one wants to wade through all that especially seeing as your using php's short tags which the boards syntax highlighting wont work with.[/quote] Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2006 Share Posted December 10, 2006 Your kidding aren't ya? The relevent code will be sufficient, no one wants to wade through all that especially seeing as your using php's short tags which the boards syntax highlighting wont work with. Quote Link to comment Share on other sites More sharing options...
stephtort Posted December 10, 2006 Author Share Posted December 10, 2006 Just forget it... I would think a global moderator would be a little more helpful. Quote Link to comment Share on other sites More sharing options...
jsladek Posted December 10, 2006 Share Posted December 10, 2006 Hi Stephanie,Looks to me like this thread was close to helping you to a solution. There were two issues that were seen right away both the extra [b]comma[/b] before the [b]WHERE[/b] clause and the lack of a value in the [b]id=''[/b]I'm not sure of how much code you pasted but the code that turns that array into SQL would have been good. I personally like to see as much code as possible but that is only because I like to see how people do different things.Don't take any comments personal here, everyone is good and helping others. Sometimes it's easy to read too much into what is written.-John Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.