Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Wont Insert Into MySQL

    It's proabably something really simple im missing, but, this code...

    PHP Code:
    if($_POST['remember'] == 'on') {
                              
    $ip $_SERVER['REMOTE_ADDR'];
                              
                              
    mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'yes' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
                         } else {
                             
    $ip $_SERVER['REMOTE_ADDR'];
                             
                              
    mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'no' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
                         } 
    Only updates 'ip' to "0" and 'remember' to "" ?

    Can you see anything?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by the-dream View Post
    It's proabably something really simple im missing, but, this code...

    PHP Code:
    if($_POST['remember'] == 'on') {
                              
    $ip $_SERVER['REMOTE_ADDR'];
                              
                              
    mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'yes' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
                         } else {
                             
    $ip $_SERVER['REMOTE_ADDR'];
                             
                              
    mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."' AND social_trees.remember = 'no' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'") or die(mysql_error());
                         } 
    Only updates 'ip' to "0" and 'remember' to "" ?

    Can you see anything?
    yes

    regards

  • #3
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    First off, why are you using "social_trees." before all your fields? You already specified "UPDATE social_trees" at the beginning, so using that is extraneous information.

    Secondly, what types are those two fields (`ip` and `remember`)? If `ip` were an INT field, that would cause an IP address to become 0 (since there are periods in the IP address, which obviously are not integers).

    And if `remember` is only ever 'yes' or 'no', it would be much better for you to make the field TINYINT(1) and have 1 = yes and 0 = no. Does that make sense?

  • #4
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    The field types are VARCHAR(255). I am happy with the way things are currently being done, if anyone knows of a way to fix it please tell me.

  • #5
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Also, you use "AND" in between the fields you are trying to set when you should be using a comma. It needs to be like this:

    PHP Code:
    mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."', social_trees.remember = 'yes' WHERE social_trees.username = '".$user."' AND social_trees.password = '".$pass."'"); 

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I would get rid of the if else statement. Try something like:



    PHP Code:
    $on_off $_POST['remember']; //      on/off or yes/no or 1/0

    $ip $_SERVER['REMOTE_ADDR'];

    mysql_query("UPDATE social_trees SET social_trees.ip = '".$ip."'
    AND social_trees.remember = "
    $on_off" WHERE social_trees.username = '".$user."'
    AND social_trees.password = '"
    .$pass."'") or die(mysql_error()); 


    ------------------
    Last edited by Len Whistler; 08-14-2008 at 06:48 PM.
    Leonard Whistler


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •