Jump to content

need help with a MySQL/PHP update form


stephtort

Recommended Posts

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.zip

Thanks in advance for any help!

Link to comment
https://forums.phpfreaks.com/topic/29550-need-help-with-a-mysqlphp-update-form/
Share on other sites

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
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]
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]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]
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]
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

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.