justinh Posted November 4, 2008 Share Posted November 4, 2008 $edit = mysql_query("UPDATE reservations SET firstname = '$firstname', description = '$description' WHERE id = '$id' && reservationdate = '$reservationdate'") or die(mysql_error()); cant seem to find out why this isnt updating the table.. thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/ Share on other sites More sharing options...
.josh Posted November 4, 2008 Share Posted November 4, 2008 $query = "UPDATE reservations SET firstname = '$firstname', description = '$description' WHERE id = '$id' && reservationdate = '$reservationdate'"; echo $query; Does this echo out your expected query string? Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682544 Share on other sites More sharing options...
justinh Posted November 4, 2008 Author Share Posted November 4, 2008 yeah.. it echo's UPDATE reservations SET firstname = 'OMGFGOK', description = 'FODGKDOGKD' WHERE id = '9' && reservationdate = '1182008' Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682547 Share on other sites More sharing options...
.josh Posted November 5, 2008 Share Posted November 5, 2008 so...are you sure there's a row in your table where id is 9 and reservationdate is 1182008 ? Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682550 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 well im pretty sure.. http://www.wmptest.com/HuntReserver/process.php?id=1182008 you can see the edit button url is getting the gets from the table edit_reservation.php <?PHP INCLUDE("connect.php"); $id = $_GET['date']; $reservationdate = $_GET['id']; $query = mysql_query("SELECT * FROM reservations WHERE id = '$id' && reservationdate = '$reservationdate'") or die(mysql_error()); while($row = mysql_fetch_array($query)){ $firstname = $row['firstname']; $description = $row['description']; } if (!isset($_POST['edit'])){ echo "<html><head><title>Hunt Reserver - Edit Reservation</title></head><body bgcolor=black><p align=center><img src=\"logo.jpeg\"><br> <table><tr><td colspan=2><p align=center><font color=white size=2><b>Edit Reservation</b></td></tr><td><font color=white size=2>First Name: </td><td><form action=\"".$_SERVER['php_self']."\" method=\"POST\"><input type=\"text\" value=$firstname name=firstname></td></tr><tr><td> <font color=white size=2>Description</td><td><input type=\"text\" value=$description name=description></td></tr><tr><td colspan=2> <p align=right><input type=\"submit\" value=\"Edit\" name=\"edit\"></form></table></body></html>"; }else{ $query = "UPDATE reservations SET firstname = '$firstname', description = '$description' WHERE id = '$id' && reservationdate = '$reservationdate'"; echo $query; echo "<html><head><title>Hunt Reserver - Edit Reservation</title></head><body bgcolor=black><p align=center><img src=logo.jpeg><br><font size=2 color=white>Reservation Edited.</body></html>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682552 Share on other sites More sharing options...
.josh Posted November 5, 2008 Share Posted November 5, 2008 Okay well offhand I'd say you got your vars transposed $id = $_GET['date']; $reservationdate = $_GET['id']; You're assigning 'date' to $id and 'id' to $reservationdate hopefully that will fix it. Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682558 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 Yes i know they are mixed up, i had to do some table editing, and i didnt really want to change all the code for every page.. but the variables are correct. Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682559 Share on other sites More sharing options...
.josh Posted November 5, 2008 Share Posted November 5, 2008 Okay so let me get this straight: You're saying that in your table, the id column holds the date, and the reservationdate column holds the id? If so...(lol?)... next guess is to again, check to make sure there is a row with 9 and 1182008 in it. Perhaps, for instance, 1182008 should be 11082008 or some other format? Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682564 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 haha your right kinda.. the variables are right but on the UPDATE query they are wrong. thanks for the catch Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682567 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 Okay it's still not working ??? I echo'd the query, took that and queried it directly into MYSQLADMIN.. this worked fine. But when i try to do it from the site it does not update. im confused Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682573 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 BUMP ??? Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682591 Share on other sites More sharing options...
l0ve2hat3 Posted November 5, 2008 Share Posted November 5, 2008 what does $query output now? add or die(mysql_error()) Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682606 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 <?PHP INCLUDE("connect.php"); $id = $_GET['date']; $reservationdate = $_GET['id']; $query = mysql_query("SELECT * FROM reservations WHERE id = '$id' && reservationdate = '$reservationdate'") or die(mysql_error()); while($row = mysql_fetch_array($query)){ $firstname = $row['firstname']; $description = $row['description']; } if (!isset($_POST['edit'])){ echo "<html><head><title>Hunt Reserver - Edit Reservation</title></head><body bgcolor=black><p align=center><img src=\"logo.jpeg\"><br> <table><tr><td colspan=2><p align=center><font color=white size=2><b>Edit Reservation</b></td></tr><td><font color=white size=2>First Name: </td><td><form action=\"".$_SERVER['php_self']."\" method=\"POST\"><input type=\"text\" value=$firstname name=firstname></td></tr><tr><td> <font color=white size=2>Description</td><td><input type=\"text\" value=$description name=description></td></tr><tr><td colspan=2> <p align=right><input type=\"submit\" value=\"Edit\" name=\"edit\"></form></table></body></html>"; }else{ $query_update = mysql_query("UPDATE reservations SET firstname = '$firstname', description = '$description' WHERE id = '$id' AND reservationdate = '$reservationdate'") or die(mysql_error()); echo "<html><head><title>Hunt Reserver - Edit Reservation</title></head><body bgcolor=black><p align=center><img src=logo.jpeg><br><font size=2 color=white>Reservation Edited.<meta http-equiv=\"refresh\" content=\"2;url=http://www.wmptest.com/huntreserver/calender.php\" /></body></html>"; } ?> reports no errors.. just says Reservation Edited. Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682612 Share on other sites More sharing options...
l0ve2hat3 Posted November 5, 2008 Share Posted November 5, 2008 is id your primary key? if so leave of reservationdate. oh and post the output. Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682616 Share on other sites More sharing options...
justinh Posted November 5, 2008 Author Share Posted November 5, 2008 id is set to primary so i took out reservationdate still the same result. the output is: Reservation Edited. ( redirects to calender.php ) <?PHP INCLUDE("connect.php"); $id = $_GET['date']; $reservationdate = $_GET['id']; $query = mysql_query("SELECT * FROM reservations WHERE id = '$id' && reservationdate = '$reservationdate'") or die(mysql_error()); while($row = mysql_fetch_array($query)){ $firstname = $row['firstname']; $description = $row['description']; } if (!isset($_POST['edit'])){ echo "<html><head><title>Hunt Reserver - Edit Reservation</title></head><body bgcolor=black><p align=center><img src=\"logo.jpeg\"><br> <table><tr><td colspan=2><p align=center><font color=white size=2><b>Edit Reservation</b></td></tr><td><font color=white size=2>First Name: </td><td><form action=\"".$_SERVER['php_self']."\" method=\"POST\"><input type=\"text\" value=$firstname name=firstname></td></tr><tr><td> <font color=white size=2>Description</td><td><input type=\"text\" value=$description name=description></td></tr><tr><td colspan=2> <p align=right><input type=\"submit\" value=\"Edit\" name=\"edit\"></form></table></body></html>"; }else{ $query_update = mysql_query("UPDATE reservations SET firstname = '$firstname', description = '$description' WHERE id = '$id'") or die(mysql_error()); echo "<html><head><title>Hunt Reserver - Edit Reservation</title></head><body bgcolor=black><p align=center><img src=logo.jpeg><br><font size=2 color=white>Reservation Edited.<meta http-equiv=\"refresh\" content=\"2;url=http://www.wmptest.com/huntreserver/calender.php\" /></body></html>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131423-mysql-update-question/#findComment-682621 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.