PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
simcityfreak4
Forum Newbie
Posts: 5 Joined: Fri Jun 22, 2007 4:50 pm
Post
by simcityfreak4 » Fri Jun 22, 2007 4:55 pm
My script has 3 input fields, and when you press submit this is the code it posts to:
Code: Select all
$idu = mysql_real_escape_string($_GET['id']);
$rid = mysql_real_escape_string($_GET['rid']);
$viewa = mysql_real_escape_string($_POST['VIEW_AVS']);
$timed = mysql_real_escape_string($_POST['VIEW_TIME']);
$timefp = mysql_real_escape_string($_POST['timefp']);
$RULEZ = "UPDATE `Members` SET `viewa` = '$viewa', `timed` = '$timed', `timef` = '$timefp' WHERE `board` = '$mboard' AND `user` = '$muser' AND `id` = '$idu'";
echo $RULEZ;
mysql_query($RULEZ);
echo mysql_error(); //Remove when released
When I echo $RULEZ I get this:
Code: Select all
UPDATE `Members` SET `viewa` = '1', `timed` = '1', `timef` = 'asdf' WHERE `board` = 'Brian' AND `user` = 'Brian' AND `id` = '3'
I took the query and ran it in phpMyAdmin and it worked fine, but when I have the script run it it just makes the fields blank.
Any ideas?
simcityfreak4
Forum Newbie
Posts: 5 Joined: Fri Jun 22, 2007 4:50 pm
Post
by simcityfreak4 » Fri Jun 22, 2007 5:10 pm
I changed it and the script doesn't die, it keeps going.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Jun 22, 2007 5:22 pm
Oh sorry, I didn't realize you had mysql_error() already in there.. try selecting the row before the update, and post the results here just so we can see if the WHERE conditions are being met
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Jun 22, 2007 5:23 pm
Since you are using an UPDATE query, try using mysql_affected_rows() to see if something was done to the row.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Jun 22, 2007 5:26 pm
What does
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', true);
$idu = mysql_real_escape_string($_GET['id']);
$rid = mysql_real_escape_string($_GET['rid']);
$viewa = mysql_real_escape_string($_POST['VIEW_AVS']);
$timed = mysql_real_escape_string($_POST['VIEW_TIME']);
$timefp = mysql_real_escape_string($_POST['timefp']);
$RULEZ = "UPDATE `Members` SET `viewa` = '$viewa', `timed` = '$timed', `timef` = '$timefp' WHERE `board` = '$mboard' AND `user` = '$muser' AND `id` = '$idu'";
echo '<div>Debug: ', $RULEZ, "</div>\n";
mysql_query($RULEZ) or die(mysql_error());
echo '<div>affcted rows: ', mysql_affected_rows(), "</div>\n";
$query = "SELECT `viewa`,`timed`,`timef` FROM `Members` WHERE `board`='$mboard' AND `user`='$muser' AND `id`='$idu'";
$result = mysql_query($query) or die(mysql_error());
echo '<table><tr><th colspan="3">', mysql_num_rows($result), '</th></tr>';
while ( false!==($row=mysql_fetch_array($result, MYSQL_ASSOC)) ) {
echo '<tr>
<td>', $row['viewa'], '</td>
<td>', $row['timed'], '</td>
<td>', $row['timef'], '</td>
</tr>';
}print?
simcityfreak4
Forum Newbie
Posts: 5 Joined: Fri Jun 22, 2007 4:50 pm
Post
by simcityfreak4 » Fri Jun 22, 2007 5:54 pm
That prints this:
Debug: UPDATE `Members` SET `viewa` = '1', `timed` = '1', `timef` = 'asdf' WHERE `board` = 'Brian' AND `user` = 'Brian' AND `id` = '3'
affcted rows: 1
1
1 1 asdf
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Jun 22, 2007 6:11 pm
Then... it's working.
simcityfreak4
Forum Newbie
Posts: 5 Joined: Fri Jun 22, 2007 4:50 pm
Post
by simcityfreak4 » Fri Jun 22, 2007 10:26 pm
Thats weird, I tried the same script in IE and it works fine, but it doesn't want to work right in FF.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Jun 22, 2007 11:39 pm
How are you checking for form submission? IE and FF send post vars a little differently at times.
simcityfreak4
Forum Newbie
Posts: 5 Joined: Fri Jun 22, 2007 4:50 pm
Post
by simcityfreak4 » Sat Jun 23, 2007 9:07 am
I got it fixed now. I just had the script post to a different page instead and had it run that same update query and it works fine now.
Thanks for everyones help!
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Jun 23, 2007 5:43 pm
The page that it is sent to really makes no difference. The same code could be included on the page the form is on, and if posted back to itself, it should work without issue.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jun 23, 2007 6:24 pm
Maybe a caching problem.