PDA

View Full Version : What's wrong with this update query?!


ConfusedOfLife
05-04-2003, 01:16 AM
Hi, I'm doing a very basic update query inside of a class, the syntax is so simple that I can't understand why it doesn't work!

Here it's a snippet of what I'm doing:

class something
{
function update($arr)
{
$query = "update newsbox set headline = 'jjj' where index = 9";
}
}


The class is somehow big and I don't bring it in here, but if it's nothing wrong with having an update query inside of a class, then I'm having a logical problem! Hey, it doesn't give me any error, it simply doesn't work! Nothing changes after running the query.

Thanks

mordred
05-04-2003, 12:18 PM
The query itself looks ok... but in your sample code you are not sending the query at all... maybe that's in the part you left out, but maybe there also lies the problem.

Always check the obvious:

1.) Send your query through phpMyAdmin to make sure it really works on the SQL side
2.) Check if you did connect succesfully to the DB in your script
3.) Check that the query was sent
4.) Use mysql_error() to get at the text of the last error message - that's usually very helpful.

and if the problem persists, provide us with more info and we help. :)

Spookster
05-04-2003, 01:43 PM
mordred is correct. You never execute the query. You have it defined in a variable but you don't execute it.

ConfusedOfLife
05-04-2003, 02:45 PM
Haha! You're right, but it's the part that I missed! I traced the problem and it's the name that I used for for my primary key field. If you look at my query, you see that I wrote:


$query = "update newsbox set headline = 'jjj' where index = 9";


And that little "index" was the source of the problem that I finally found out after sleeping 3 hours. You know, you miss some certain things if you don't sleep for 2 days!