php - Delete topic from database -


i have code allows user delete own topics. it's working in case user not 1 posted topic, still getting message: topic has been deleted, whereas should get: didnt make topic. else statement isnt running.

if(isset($_session['username'])) {     $uid = $_session['uid'];      $id=$_get['id'];      $check = mysql_query("select * topics id = '$id' , topiccreator = '$uid'");     if($check){         $query1=mysql_query("delete topics id='$id' , topiccreator='$uid'");         echo "<p>topic has been deleted. <a href='index.php'>click here return home page.</a>";     }     else{         echo "<p><b>error: didnt make topic.";     } } 

i dont know why else statement wont run.

$check see if user logged in 1 created topic.

(ps: i'll switch mysqli once works.)

as comments suggest, can't check against resource itself. try:

if(isset($_session['username'])) {     $uid = $_session['uid'];      $id=$_get['id'];     $check = mysql_query("select * topics id = '$id' , topiccreator = '$uid'");     $count = mysql_num_rows($check);     if($count) {         // $count greater 1 hence true         $query1=mysql_query("delete topics id='$id' , topiccreator='$uid'");         echo "<p>topic has been deleted. <a href='index.php'>click here return home page.</a>";     } else{         // $count 0 or false - no rows returned         echo "<p><b>error: didnt make topic.";     } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -