Help!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Help!!

Post by potato »

Does somebody sees the fault in this query?


$query = mysql_query("UPDATE bands SET band_name='$name' band_hoofdgenre='$genre' band_subgenre='$subgenre' band_location='$location' band_website='$website' band_info='$info' WHERE band_id='$bandid'")or exit('Not updated!');
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

Try it without the quotes around $bandid
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

seems like you should use INSERT instead of UPDATE
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

try this

Code: Select all

$query = mysql_query("UPDATE bands SET band_name='".$name."', band_hoofdgenre='".$genre."', band_subgenre='".$subgenre."', band_location='".$location."', band_website='".$website."', band_info='".$info."' WHERE band_id='".$bandid."'")or exit('Not updated!');
Last edited by PrObLeM on Tue Mar 16, 2004 4:49 pm, edited 1 time in total.
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post by coreycollins »

Try putting commas between each item.
For example:

Code: Select all

$query = mysql_query("UPDATE bands SET band_name='$name', band_hoofdgenre='$genre', band_subgenre='$subgenre', band_location='$location', band_website='$website', band_info='$info' WHERE band_id=$bandid")or exit('Not updated!');
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

tim wrote:seems like you should use INSERT instead of UPDATE
tim makes a good point. Are you trying to enter new data or change already existing data?
User avatar
potato
Forum Contributor
Posts: 192
Joined: Tue Mar 16, 2004 8:30 am
Location: my lovely trailer, next to the big tree

Post by potato »

Allright, i found it.

It were the commas that i forgot.

Thanx everybody
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

1 question to tim and phuts: how could he insert new data into an existing band_id?? He is obviously trying to edit existing data, or else there would be no need for the WHERE clause
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

Illusionist wrote:1 question to tim and phuts: how could he insert new data into an existing band_id?? He is obviously trying to edit existing data, or else there would be no need for the WHERE clause
who knows.. but I do things like that all the time, usually because I forget the syntax / feel lazy and copy some code I've already typed. Sometimes I end up completely forgetting my original intent after making such a mistake (ie updating versus inserting). granted a WHERE clause in this code should be a redflag, but i could see myself having forgotten what exactly it is I was trying to do, so maybe it happens to others.

then again, many people aren't as thoughtless as I :)
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

if he would have clarified that he was intending to 'edit' using the sql statement, i wouldnt have bothered refering the INSERT command. I dont assume certain things, yes the WHERE clause is a good hint the statement was for editing purposes, but no offsense to bev he might not of known any better.

By the quick glance, he looked like he was adding data, just the way I see things when I glance over it.

my fault, apologies
Post Reply