kaos Posted June 28, 2010 Share Posted June 28, 2010 if($_GET[delete]) { if($mod == "0") { die('You cannot delete this topic'); } $delete = $_GET[delete]; $cc=mysql_num_rows(mysql_query("SELECT * FROM forum_question WHERE username='$username' AND id='$delete'")); $fet=mysql_query("SELECT * FROM forum_question AND id='$delete'"); if($mod == 2){ mysql_query("DELETE FROM forum_question WHERE id='$delete'"); mysql_query("DELETE FROM forum_answer WHERE question_id='$delete'"); mysql_query("UPDATE forum_user SET post=post-1 WHERE username='$fet->username'"); } echo "Topic Deleted."; echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL=index.php'>"; } Any idea why it dosent UPDATE forum_user SET post=post-1? Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/ Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 $fet is a result resource, your treating as though it where an object. Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078164 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 So what do i need to change? mysql_fetch_object? Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078175 Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 Yes, $fet will need to be passed to mysql_fetch_object. Its not the only error though. You really should check your queries actually execute before continuing. The second SELECT statement will fail, its missing any WHERE clause. It should be combined with the first one anyway for efficiencies sake. Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078179 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 Its ment to be WHERE not and i think lol thanks Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078180 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 $fet=mysql_query(mysql_fetch_object("SELECT * FROM forum_question WHERE id='$delete'")); this now says isnt a valid mysql result resource Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078182 Share on other sites More sharing options...
Adam Posted June 28, 2010 Share Posted June 28, 2010 They're the wrong way round. Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078188 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 Works like a charm thanks now fr my other topic.... Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078190 Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 $fet=mysql_query(mysql_fetch_object("SELECT * FROM forum_question WHERE id='$delete'")); this now says isnt a valid mysql result resource This is a terrible way of executing queries because you have no checks in place to see if they actually succeed. In fact, writing code like that leaves no opportunity to fit a check in. At minimum a SELECT statement should be executed something like.... $sql = "SELECT * FROM forum_question WHERE id='$delete'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result is now safe to use in here. } else { // no results where found, handle the error } } else { // your query failed, handle the error } Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078241 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 Fixed forgot the mysql_fetch_object again Link to comment https://forums.phpfreaks.com/topic/206058-dosent-update-forum_user/#findComment-1078247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.