djmelle Posted April 13, 2009 Share Posted April 13, 2009 Hi! I've made a script which gets posts from a database which needs to be accepted before it's put on the site. but when I try to update a post on the admin page I've made some kind of mistake since it always update the last id in the database thats need to be accepted and not the actual one you click on. here's the full code: <?php include("header.php"); ?> <?php if(isset($_POST['acc'])) { $accid = $_POST['accid']; $update=mysql_query("update fansaker set acc='1' where 'id'='$accid'"); } ?> <?php $adminsql=mysql_query("select * from fansaker where acc = 0 order by id"); print "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>"; print "<form name=acc' method='post' action='acc.php'>"; while($n1=mysql_fetch_array($adminsql)){ print "<tr><td><b>id:</b> <input type='hidden' name='accid' value='$n1[id]'>$n1[id]</td>"; print "<tr bgcolor=#f1f1f1><td colspan=2>$n1[comment] <b>FTML</b></td></tr>"; print "<tr><td><input type='submit' name='acc' value='accept'> <input type='submit' name='del' value='delete'></td></tr>"; } print "</table>"; ?> any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/153859-solved-update-database-in-specific-id/ Share on other sites More sharing options...
ober Posted April 13, 2009 Share Posted April 13, 2009 Echo your query before you execute it. Is it getting the right value? Look at the source of the page where it lists out the unaccepted rows. Is it getting the right value? Quote Link to comment https://forums.phpfreaks.com/topic/153859-solved-update-database-in-specific-id/#findComment-808598 Share on other sites More sharing options...
djmelle Posted April 13, 2009 Author Share Posted April 13, 2009 hi, yep when I echo the id in the formular (the red) I have the right id print "<tr><td><b>id:</b> <input type='hidden' name='accid' value='$n1[id]'>$n1[id]</td>"; but when I send it to update the script it always the last id, I've tried to echo here before updating the databas and it always gives me the last id... Quote Link to comment https://forums.phpfreaks.com/topic/153859-solved-update-database-in-specific-id/#findComment-808604 Share on other sites More sharing options...
ober Posted April 13, 2009 Share Posted April 13, 2009 It is impossible to go from the form with the right value to the processing with the wrong value, so you are obviously passing the wrong ID. Quote Link to comment https://forums.phpfreaks.com/topic/153859-solved-update-database-in-specific-id/#findComment-808618 Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 1) You don't need single quotes around 'id' in your query. Change it to this and see if it makes a difference or outputs any errors. $update=mysql_query("update fansaker set acc='1' where id='$accid'") or die(mysql_error()); 2) You need to end your form. 3) Like ober said, the value is not going to magically change from the form to the action script if that's your entire code. Quote Link to comment https://forums.phpfreaks.com/topic/153859-solved-update-database-in-specific-id/#findComment-808744 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.