Results 1 to 4 of 4

Thread: [RESOLVED] DELETE return value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Resolved [RESOLVED] DELETE return value

    i have the following that i can delete my records with no problem but if you enter a records that doesnt exist then i need to be able to get a return value that tells the user you cant delete that cause it doesn't exist. with my SELECT statements or UPDATE i do $num=mysql_numrows($result); and test the vaule of $num, but i cant with the following

    Code:
    $query = "DELETE FROM WorkOrders WHERE id='$TicketNumber' AND siteid='$siteid'";
    
    $result=mysql_query($query);
    i want to be able to via the $result value see if the record even exist then i can tell the user that it either doesn't or it was deleted.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: DELETE return value

    use mysql_affected_rows() for INSERT, UPDATE and DELETE. mysql_num_rows() only returns the number of rows found (meaning only for SELECT).
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: DELETE return value

    Kows,

    thanks once again. that did it. for those interested here is my entire delete with a redirect if not found.

    Code:
    $query = "DELETE FROM WorkOrders WHERE id='$TicketNumber' AND siteid='$siteid'";
    
    $result=mysql_query($query);
    
    $result = mysql_affected_rows();
    
    mysql_close();
    
    
    
    if($result == "0"){
    
    	echo "<br><center><font size=\"2\"><b>That Ticket number doesn't exist in your datebase. It may have already been deleted. You will now be redirected back to the main page.</b></font></center>";
    	
    	//below will redirect the uese to another page when completed
    $url = 'http://www.yoursite.com/main.php';
     
    //directory.
    
    $content = 4;
    exit("
           <meta
           http-equiv=\"refresh\"
           content=\"{$content};url={$url}\"
           >
           <script>
           function doRefresh() {
               window.location = '{$url}';
           }
           doRefreshTimeout = setTimeout(\"doRefresh()\" , ".
    ($content*200000).");
           </script>
       ");
    //done with redirecting 
    }
    
    else{	
    
    
    echo "<br><center><font size=\"2\"><b>Ticket # $TicketNumber Has Been Deleted. </b></font></center>";
    
    }

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] DELETE return value

    it's better to use headers than JavaScript if you want to redirect; you can always show the error message on the next page.

    PHP Code:
    // Redirect
    header("Location: " $url); 
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width