|
-
Oct 23rd, 2010, 10:52 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Oct 24th, 2010, 12:14 AM
#2
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).
-
Oct 24th, 2010, 09:03 AM
#3
Thread Starter
Hyperactive Member
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>";
}
-
Oct 24th, 2010, 10:44 AM
#4
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);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|