How do I return result of mysql row deletion

This is a discussion on How do I return result of mysql row deletion within the PHP Language forums, part of the PHP Programming Forums category; Can someone please advise me on how to implement this? The data entered by a user on form 1 on ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-13-2007
Big Moxy
 
Posts: n/a
Default 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!

Reply With Quote
  #2 (permalink)  
Old 08-13-2007
Rik
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

On Mon, 13 Aug 2007 19:53:18 +0200, Big Moxy <bigmoxy@gmail.com> wrote:

> 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
Reply With Quote
  #3 (permalink)  
Old 08-13-2007
burgermeister01@gmail.com
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.com> wrote:
> 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.

Reply With Quote
  #4 (permalink)  
Old 08-13-2007
Big Moxy
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
> On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.com> wrote:
>
> > 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));

Reply With Quote
  #5 (permalink)  
Old 08-13-2007
Jerry Stuckle
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

Big Moxy wrote:
> On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
>> On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.com> wrote:
>>
>>> 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.
jstucklex@attglobal.net
==================
Reply With Quote
  #6 (permalink)  
Old 08-13-2007
Rik
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

On Mon, 13 Aug 2007 21:21:11 +0200, Big Moxy <bigmoxy@gmail.com> wrote:

> On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
>> On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.com> wrote:
>>
>> > 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
Reply With Quote
  #7 (permalink)  
Old 08-13-2007
Big Moxy
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

On Aug 13, 1:29 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
> On Mon, 13 Aug 2007 21:21:11 +0200, Big Moxy <bigm...@gmail.com> wrote:
> > On Aug 13, 12:44 pm, burgermeiste...@gmail.com wrote:
> >> On Aug 13, 12:53 pm, Big Moxy <bigm...@gmail.com> wrote:

>
> >> > 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>

Reply With Quote
  #8 (permalink)  
Old 08-14-2007
Jerry Stuckle
 
Posts: n/a
Default Re: How do I return result of mysql row deletion

Big Moxy wrote:
> On Aug 13, 1:29 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
>
> 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.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:31 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0