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
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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.