Problem with updating a mySQL database

Jon208

Junior Member
Jan 12, 2008
2
0
0
I'm trying to teach myself php and mySQL. I've been having problems updating my database through an HTML form. I can add to the database with no problem but I cant figure out how to update it. Could anyone help me through this?
Thanks for any help!


This is the code I'm using to submit the form to the database...

 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
Try using that exact syntax in the mySQL CLI (put in dummy values). If that works, then verify the data type to make sure it agrees with the field of the database.

Also check the logs for the browser and mySQL and see if they have an understandable error

The usual problem is you're not hitting your "where" clause, bad data type, hanging (or missing) space (so two commands or fields concatenate themselves into a syntax error) ... stuff like that.

Good Luck

Scott

 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
we need errors!

mysql_query($insert) or die("SQL error: " . mysql_error());
 

Jon208

Junior Member
Jan 12, 2008
2
0
0
The weirdest thing is that it doesn't return any errors the script runs just fine. I've been using phpmyadmin to edit and look at the database. I took the update SQL command from phpMyadmindo I maybe have the fields from the forms being posted wrong?
 

Hyperblaze

Lifer
May 31, 2001
10,027
1
81
Originally posted by: ScottMac
Try using that exact syntax in the mySQL CLI (put in dummy values). If that works, then verify the data type to make sure it agrees with the field of the database.

Also check the logs for the browser and mySQL and see if they have an understandable error

The usual problem is you're not hitting your "where" clause, bad data type, hanging (or missing) space (so two commands or fields concatenate themselves into a syntax error) ... stuff like that.

Good Luck

Scott

I'd recommend setting up phpMyAdmin (it's free) and has a very nice GUI to use for SQL commands.

also.....

I'd HIGHLY recommend you break down your code in multiple lines for easier reading.

when you are trying to find an error somewhere, the last thing you need is SQL code which is all one line which is making it insanely difficult to debug.


UPDATE `tbl`
SET `blah` = <whatever>,
`blah2` = whatever,
`blah3` = whatever
WHERE `blah1` = whatever2
AND `blah5` = whatever5

(it's how I would write it. Might take more space and lines, but it's quick and easy to read. Quick and easy beats everything in one line any day)