Re: if() and else() help needed

From: Date: Tue, 28 Mar 2006 01:06:16 +0000
Subject: Re: if() and else() help needed
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-41617@lists.php.net to get a copy of this message
JeRRy wrote:
Hi, I'll admit it, this is damned messy. But I want to learn from the list in how to sort it out. Than for future refrence I will know... Now I am running 2 different queries/statements here completely seperate. I have made the "nickname" field in the database UNIQUE. So than when I have this sort of query setup no matter what their will only be one "nickname" entry for that user. So when people update their profile a new "nickname" is not inserted but it is updated. But I want it all in one PHP call. How do I do this?
How are you differentiating between the statements? eg they are logged in, or you check with a database query or .... ? You could do something like this: // check for $_GET['tipid'] - if it's there, we're updating our tips. // if it's not, then we're adding new tips. if (isset($_GET['tipid'])) { $query = "UPDATE " ...... $success_message = "Your tips have been updated"; } else { $query = "INSERT INTO " ..... $success_message = "Your tips have been saved"; } $result = mysql_query($query); if ($result) { echo $success_message; } else { echo "Problem!!<br/>"; } -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#41617) next »