473,219 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

How do I return result of mysql row deletion

Can someone please advise me on how to implement this?

The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.

How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?

Thank you!

Aug 13 '07 #1
7 1931
Rik
On Mon, 13 Aug 2007 19:53:18 +0200, Big Moxy <bi*****@gmail.comwrote:
Can someone please advise me on how to implement this?

The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.

How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?
mysql_affected_rows() will tell you how many rows are affected by the
DELETE statement. Store the success or failure in a session at delete.php,
read it out in page1.php.
--
Rik Wasmus
Aug 13 '07 #2
On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.comwrote:
Can someone please advise me on how to implement this?

The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.

How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?

Thank you!
Another option is this:
mysql_query() will return false if an error occurs, so if you put your
execute statement in an if statement as following you can get a
boolean success/failure response:
if(mysql_query()){
return "Yay! Success";
}else{
return "Failure";
}

Additionally, mysql_error() can tell you what went wrong.

Aug 13 '07 #3
On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.comwrote:
Can someone please advise me on how to implement this?
The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.
How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?
Thank you!

Another option is this:
mysql_query() will return false if an error occurs, so if you put your
execute statement in an if statement as following you can get a
boolean success/failure response:
if(mysql_query()){
return "Yay! Success";}else{

return "Failure";

}

Additionally, mysql_error() can tell you what went wrong.
Apparently today is not my lucky day. When no row is deleted the URL
is pointing to my delete.php and not page1.php yet the browser display
seems to refresh.

BTW I got the same result with the mysql_affected_rows().

Here is a snippet of the delete.php code -

$Result1 = mysql_query($deleteSQL, $emailmanager) or
die(mysql_error());
if (mysql_query()) {
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}
else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}
$deleteGoTo = "/casper/emailmanager.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));

Aug 13 '07 #4
Big Moxy wrote:
On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
>On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.comwrote:
>>Can someone please advise me on how to implement this?
The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.
How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?
Thank you!
Another option is this:
mysql_query() will return false if an error occurs, so if you put your
execute statement in an if statement as following you can get a
boolean success/failure response:
if(mysql_query()){
return "Yay! Success";}else{

return "Failure";

}

Additionally, mysql_error() can tell you what went wrong.

Apparently today is not my lucky day. When no row is deleted the URL
is pointing to my delete.php and not page1.php yet the browser display
seems to refresh.

BTW I got the same result with the mysql_affected_rows().

Here is a snippet of the delete.php code -

$Result1 = mysql_query($deleteSQL, $emailmanager) or
die(mysql_error());
if (mysql_query()) {
Why are you calling mysql_query() again? You want to test $Result1 -
which you already did with die() (a bad choice here!).
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}
else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}
$deleteGoTo = "/casper/emailmanager.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
Rather:

if (mysql_query($deleteSQL,$emailmanager) && mysql_affected_rows()>0)) {
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}
else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}

(sorry about the wrapping).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '07 #5
Rik
On Mon, 13 Aug 2007 21:21:11 +0200, Big Moxy <bi*****@gmail.comwrote:
On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
>On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.comwrote:
Can someone please advise me on how to implement this?
The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.
How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?
Thank you!

Another option is this:
mysql_query() will return false if an error occurs, so if you put your
execute statement in an if statement as following you can get a
boolean success/failure response:
if(mysql_query()){
return "Yay! Success";}else{

return "Failure";

}

Additionally, mysql_error() can tell you what went wrong.

Apparently today is not my lucky day. When no row is deleted the URL
is pointing to my delete.php and not page1.php yet the browser display
seems to refresh.

BTW I got the same result with the mysql_affected_rows().

Here is a snippet of the delete.php code -

$Result1 = mysql_query($deleteSQL, $emailmanager) or
die(mysql_error());
if (mysql_query()) {
The previous code was just an illustration. In this case it should be:

$Result1 = mysql_query($deleteSQL, $emailmanager);
if($Result1 && mysql_affected_rows()){
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}
else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}
$deleteGoTo = "/casper/emailmanager.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $deleteGoTo));
Actually, you should try to get a full URL in the redirect (possibly by
using 'http://'.$_SERVER['HTTP_HOST'].$deleteGoTo). Officially it's
required, allthough most user agents can handle relative URL's quite well
one shouldn't rely on it.
--
Rik Wasmus
Aug 13 '07 #6
On Aug 13, 1:29 pm, Rik <luiheidsgoe...@hotmail.comwrote:
On Mon, 13 Aug 2007 21:21:11 +0200, Big Moxy <bigm...@gmail.comwrote:
On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.comwrote:
Can someone please advise me on how to implement this?
The data entered by a user on form 1 on page1.php is posted to
delete.php to remove that row from a table. After the SQL operation
the user is returned to page1.php.
How can I determine the success or failure of the SQL operation so I
can display an appropriate response message to the user?
Thank you!
Another option is this:
mysql_query() will return false if an error occurs, so if you put your
execute statement in an if statement as following you can get a
boolean success/failure response:
if(mysql_query()){
return "Yay! Success";}else{
return "Failure";
}
Additionally, mysql_error() can tell you what went wrong.
Apparently today is not my lucky day. When no row is deleted the URL
is pointing to my delete.php and not page1.php yet the browser display
seems to refresh.
BTW I got the same result with the mysql_affected_rows().
Here is a snippet of the delete.php code -
$Result1 = mysql_query($deleteSQL, $emailmanager) or
die(mysql_error());
if (mysql_query()) {

The previous code was just an illustration. In this case it should be:

$Result1 = mysql_query($deleteSQL, $emailmanager);
if($Result1 && mysql_affected_rows()){
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}
else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}
$deleteGoTo = "/casper/emailmanager.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $deleteGoTo));

Actually, you should try to get a full URL in the redirect (possibly by
using 'http://'.$_SERVER['HTTP_HOST'].$deleteGoTo). Officially it's
required, allthough most user agents can handle relative URL's quite well
one shouldn't rely on it.
--
Rik Wasmus- Hide quoted text -

- Show quoted text -
Well, perhaps I'm getting closer. The URL is now page1.php but now
results message is not displayed. I've passed $_SESSION variables
forward before but not back. The method I used for forward passing is

session_start();
foreach ($_POST as $key =$value) {
$_SESSION[$key] = $value;
}

I tried that but it did not work in this scenario.
Here is the delete code -

if (mysql_query($deleteSQL,$emailmanager) &&
mysql_affected_rows()>0) {
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}

$deleteGoTo = "/casper/page1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", "http://".$_SERVER['HTTP_HOST'].
$deleteGoTo));

Here is the page1 code -

$result_message = "";
if ((isset($_SESSION['mysql_query_result'])) &&
($_SESSION['mysql_query_result'] != "")) {
$result_message = $_SESSION['mysql_query_result'];
}

....

<td align="center" colspan="2">
<?php
echo $result_message;
?>
</td>

Aug 13 '07 #7
Big Moxy wrote:
On Aug 13, 1:29 pm, Rik <luiheidsgoe...@hotmail.comwrote:

Well, perhaps I'm getting closer. The URL is now page1.php but now
results message is not displayed. I've passed $_SESSION variables
forward before but not back. The method I used for forward passing is

session_start();
foreach ($_POST as $key =$value) {
$_SESSION[$key] = $value;
}

I tried that but it did not work in this scenario.
Here is the delete code -

if (mysql_query($deleteSQL,$emailmanager) &&
mysql_affected_rows()>0) {
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}

$deleteGoTo = "/casper/page1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", "http://".$_SERVER['HTTP_HOST'].
$deleteGoTo));

Here is the page1 code -

$result_message = "";
if ((isset($_SESSION['mysql_query_result'])) &&
($_SESSION['mysql_query_result'] != "")) {
$result_message = $_SESSION['mysql_query_result'];
}

...

<td align="center" colspan="2">
<?php
echo $result_message;
?>
</td>
Do you have a session_start() call at the beginning of your second page,
also?

When you look at the page source in your browser, do you see the
"<td>..</td>" in there?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Walker | last post by:
Hi I have a Microsoft SQL database I can use (also mySQL, so if you know how to do this in mySQL that is just as useful). The database can only be accessed from webpages hosted on the same server...
9
by: Börni | last post by:
Hi, I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But...
1
by: Ellery Leung | last post by:
Hi all. Below is the php code (Very simple): <?php include_once('C:\AppServ\php\PEAR\DB.php'); $db = DB::connect("mysql://alucard@localhost:3306/soccer");...
0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data in one table. All data in that table are gone...
1
by: Chagh | last post by:
hi all, how can we have a select satement in an SP?(i want to return a result set from the SP). i want to migrate from SQL Server to MySQL and i don’t know what to do with these SPs. it can be...
4
by: Bob Bedford | last post by:
We have no access to a mysql NG on my provider's server, so we ask here: We have a long query (long in text) with a UNION between 2 select. We have been informed that some times the query...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
5
by: Bob Bedford | last post by:
Hello, I'm doing a select in wich I retrieve some values. If the value is in an array, I must delete the record. As I'm doing a "mysql_fetch_object", may I delete this record inside the...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.