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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -