Shoutbox

PHP - die function - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP - die function (/showthread.php?tid=62442)

PHP - die function by absorbation on 07-03-2006 at 04:50 PM

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.
RE: PHP - die function by Plik on 07-03-2006 at 05:10 PM

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


RE: PHP - die function by absorbation on 07-03-2006 at 05:11 PM

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?
RE: PHP - die function by absorbation on 07-03-2006 at 05:18 PM

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 :).
RE: PHP - die function by WDZ on 07-04-2006 at 03:42 AM

mysql_query() will not return false just because no rows were updated!

Try mysql_affected_rows()


RE: PHP - die function by andrewdodd13 on 07-04-2006 at 08:50 AM

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