homepage Welcome to WebmasterWorld Guest from 54.211.230.186
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
UPDATE coming back successful but not changing db
Sarah Atkinson

10+ Year Member



 
Msg#: 8174 posted 5:47 pm on May 11, 2005 (gmt 0)

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
$date=$_POST['date'];
$maincourse=$_POST['maincourse'];
$veggie=$_POST['veggie'];
$veggie2=$_POST['veggie2'];
$fruit=$_POST['fruit'];
$dessert=$_POST['dessert'];
$drink=$_POST['drink'];
$bread=$_POST['bread'];
$fromwhere=$_POST['fromwhere'];
$xdate=$_POST['xdate'];
$zdate=$_POST['zdate'];

$ok1 = @mysql_query("UPDATE $fromwhere SET
day='$day',
maincourse='$maincourse',

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

 

ergophobe

WebmasterWorld Administrator ergophobe us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 8174 posted 6:19 pm on May 11, 2005 (gmt 0)

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.

kreeves

10+ Year Member



 
Msg#: 8174 posted 7:18 pm on May 11, 2005 (gmt 0)

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

10+ Year Member



 
Msg#: 8174 posted 7:24 pm on May 11, 2005 (gmt 0)

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.

kreeves

10+ Year Member



 
Msg#: 8174 posted 7:42 pm on May 11, 2005 (gmt 0)

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.

It's YYYY-MM-DD

[dev.mysql.com...]

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

Sarah Atkinson

10+ Year Member



 
Msg#: 8174 posted 2:47 pm on May 12, 2005 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved