What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP - die function

PHP - die function
Author: Message:
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
O.P. PHP - die function
Can someone tell me what is wrong with this code:

code:
mysql_query("update referals2 set amount=(amount+1) where website='$referal'") or die (mysql_query("insert into referals2 values('','$referal','')"));

It is simple really, update the feild, but if there is no feild to update add a new one. However, never using the die function before is it designed to echo text or act as an else statement for mysql queries? Thanks :)

If you can also give me some right code or a better funtion to use when it comes to mysql queries, that would be great as well.
07-03-2006 04:50 PM
Profile PM Find Quote Report
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
34 / Male / –
Joined: Jun 2004
RE: PHP - die function
die echos the parameter you give it, then ends the current scripts execution.
As ever, if you're in doubt about a php function, look it up on php.net http://www.php.net/die

This post was edited on 07-03-2006 at 05:11 PM by Plik.
07-03-2006 05:10 PM
Profile PM Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
O.P. RE: PHP - die function
quote:
Originally posted by Plik


die echos the parameter you give it, then ends the current scripts execution.

So it could not be used to sumbit another query? Then what could I use :P?
07-03-2006 05:11 PM
Profile PM Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
O.P. RE: PHP - die function
quote:
Originally posted by thekid
mysql_query will return false if there's an error.

that's perfect for me then, I'll test it now, thanks :).
07-03-2006 05:18 PM
Profile PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP - die function
mysql_query() will not return false just because no rows were updated!

Try mysql_affected_rows()
07-04-2006 03:42 AM
Profile PM Web Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
RE: PHP - die function
This is what I'd use (off the top of my head):

code:
$query1 = "update referals2 set amount=(amount+1) where website='$referal'";
$query2 = "insert into referals2 values('','$referal','')";

mysql_query($query1) or die ("Failed to update the database, this is a connection / database not exist problem.");

if (mysql_affected_rows() == 0) {
mysql_query($query2) or die ("Failed to insert new record, this is a connection / database problem.");
}

You'll probably also want to query query1 after query2, if I get the way your thing works :)
[Image: AndrewsStyle.png]
07-04-2006 08:50 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On