Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

UPDATE coming back successful but not changing db


Sarah Atkinson

5:47 pm on May 11, 2005 (gmt 0)

10+ Year Member

Here is my code.
echo '<p>item updated successfully!</p>'; is triggered but db is not changed.
$_POST verriables are successfully passed to the PHP verriables.

if (isset($_POST['change'])): //if updates have been entered and need to be

$ok1 = @mysql_query("UPDATE $fromwhere SET

WHERE id='$id'");
if ($ok1) {
echo '<p>item updated successfully!</p>';
} else {
echo '<p>Error updating item in database!<br />'.
'Error: ' . mysql_error() . '</p>';


6:19 pm on May 11, 2005 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

echo your query and see if it's what you want. For example, assuming that $id is not getting set properly you'll have

WHERE id='';

That is valid and will be successful as far as MySQL is concerned, but since it won't find a row with an id of '', no rows will be updated.


7:18 pm on May 11, 2005 (gmt 0)

10+ Year Member

Add this to your code. This is what the end of it should look like.

WHERE id='$id'") or trigger_error(mysql_error());

This will give you an idea on if your program is erroring on the mysql query and on what part of the query.

The reason your program always says it's successful is because you have it checking if a variable has any information in it just after you assign it all kinds of information. It will always be true.

If you want to check to see if the query actually completes, do an if statement on the mysql_affected_rows().

if (mysql_affect_rows > 0) instead of $ok1 .

Sarah Atkinson

7:24 pm on May 11, 2005 (gmt 0)

10+ Year Member

The problem was that i didn't pass the id to it... opps guess that was kind of important.

Now the only problem I have is that the day seems to set itself to 0000-00-00.


7:42 pm on May 11, 2005 (gmt 0)

10+ Year Member

I messed up in my post too.

It's mysql_affected_rows() not what I put above

On your problem, how are you getting the date? Is the date row in your table set to DATE in MySQL?

If so, it needs to fit a certain structure.



EDIT: Didn't notice you had it that way already. I would make sure it's submitting correctly though.

Sarah Atkinson

2:47 pm on May 12, 2005 (gmt 0)

10+ Year Member

Got the Date working. I changed the structure for display when quering to read something like Tue, Oct. 8. When I copied and pasted the sql query
(hey it was a long query and I'm to lazy to retype it) I had to delete that

Featured Threads

Hot Threads This Week

Hot Threads This Month