Jump to content

arre

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by arre

  1. [!--quoteo(post=369387:date=Apr 27 2006, 05:30 PM:name=zanus)--][div class=\'quotetop\']QUOTE(zanus @ Apr 27 2006, 05:30 PM) [snapback]369387[/snapback][/div][div class=\'quotemain\'][!--quotec--] you could much easier do the IF in the query itself like so [code] $sql = " IF ( SELECT name FROM bUser where name = '$name' IS NULL ) THEN      INSERT INTO bUser Values ('$name','$mail'); ELSE      UPDATE bUser SET email = '$mail' where name = '$name'; END IF; "; mysql_query($sql);[/code] I think that should work [/quote] That seems logical zanus.. got a "prepare fails" error though. Maybe I'm doing something wrong :S.. is spacing sensitive when writing the if function inside the sql query?
  2. I tried to run the code-example you gave me bbaker, but now it only inserts. How does the code compare the name if it's already in the database?
  3. [!--quoteo(post=369247:date=Apr 27 2006, 09:45 AM:name=micah1701)--][div class=\'quotetop\']QUOTE(micah1701 @ Apr 27 2006, 09:45 AM) [snapback]369247[/snapback][/div][div class=\'quotemain\'][!--quotec--] check your operator in the if() statement. you have !== for "is not equal to" you only need != check out [a href=\"http://www.w3schools.com/php/php_operators.asp\" target=\"_blank\"]http://www.w3schools.com/php/php_operators.asp[/a] [/quote] Thx for replying.. changed it to != , still doesn't work :(
  4. I want to be able to switch between two sql statements.. I'm sending the values through a form calling the function below :) [code] ////////////////////////////////////////////////// function checkUser($name,$mail) {   $conn_id = ifx_connect ("db@atkin")     or die("Cant open database");   $query = "SELECT name FROM bUser where name == '$name'";   $result = ifx_query ($query, $conn_id)     or die("Cant SELECT");   if ($result !== null)     {       print "UPDATE";       $query = "UPDATE bUser SET email = '$mail' where name == '$name'";       $result = ifx_query ($query, $conn_id)         or die("Cant UPDATE");     } else {       print "INSERT";       $query = "INSERT INTO bUser Values ('$name','$mail')";       $result = ifx_query ($query, $conn_id)         or die("Cant INSERT");     }   ifx_free_result($result);   ifx_close($conn_id); } ?> [/code] -------------------------------------- Well, the idea is to update the email of a person if that person exists in the database. If not then add him/her to the database. But the If statement doesn't work, the only thing that works is the update query. When I try to print $result to see whether it's null or not I see that it contains a string "Resource id2".. so that's why the update query works and not the insert. Shouldn't $result be null if name doesn't exist? Thx in advande :)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.