You are here: Re: How do I return result of mysql row deletion « PHP Programming Language « IT news, forums, messages
Re: How do I return result of mysql row deletion

Posted by Rik on 08/13/07 19:29

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 you=
r
>> 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 =3D 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 =3D mysql_query($deleteSQL, $emailmanager);
if($Result1 && mysql_affected_rows()){

> $_SESSION["mysql_query_result"] =3D "Your email address has been
> successfully removed";
> }
> else {
> $_SESSION["mysql_query_result"] =3D "Your email address was not
> found. Please try again";
> }
> $deleteGoTo =3D "/casper/emailmanager.php";
> if (isset($_SERVER['QUERY_STRING'])) {
> $deleteGoTo .=3D (strpos($deleteGoTo, '?')) ? "&" : "?";
> $deleteGoTo .=3D $_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 wel=
l =

one shouldn't rely on it.
-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация