No entries in database even though form submitted successfully? What could be wrong?

Discussion in 'PHP' started by crumblepie, Jun 16, 2012.

  1. #1
    Here is the code:

    $values = 'VALUES ("'.$user_name.'", "'.$user_name.'", "'.$user_name.'", "'.$user_pass.'", "'.$user_email.'", "'.user_ip.'")';
    		$insert = mysql_query("INSERT INTO member(user_name, bidder_name, seller_name, user_pass, user_email, user_ip) " .$values);
    		if($insert)
    		{
    				///Yippie it's done, now ask that guy to login
    				header('location: login.php');
    		}
    	}
    mysql_close($conn);
    ?>
    PHP:
    In the member database, the columns are user_name, bidder_name, seller_name, user_pass, user_ip, user_email in that order. The registration form just asks for username, password and e-mail address. I am using
    PHP version 5.3.10
    MySQL version 5.0.95-community

    What could be wrong? How come when someone submits the form and it says it's successful, but there are no entries in the database?
     
    crumblepie, Jun 16, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Try
    
            if(mysql_query("INSERT INTO member VALUES('$user_name', NULL, NULL, '$user_pass', NULL, '$user_email');"))
            {
                    ///Yippie it's done, now ask that guy to login
                    header('location: login.php');
            }
    
    PHP:
    Make sure you've protected those variables against SQL injection attacks before you use them.
     
    Rukbat, Jun 16, 2012 IP
  3. crumblepie

    crumblepie Well-Known Member

    Messages:
    2,612
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Thank you Rukbat. I've tried it but it created an empty row in the database again :(
     
    crumblepie, Jun 16, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    At the time the query executes, what are the values of $user_name, $user_pass and $user_email? If they're empty or null, you'll get an empty row.
     
    Rukbat, Jun 16, 2012 IP
  5. crumblepie

    crumblepie Well-Known Member

    Messages:
    2,612
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Nah, I wrote something in each field. I'm wondering.. could this have something to do with me upgrading my mysql version?
     
    crumblepie, Jun 17, 2012 IP
  6. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #6
    You're beating a dead horse here. Noone here cares about SQL Injection or have the slightest idea what it is or how to avoid it. Even if you tell them...it goes on one ear and out the other.
     
    NetStar, Jun 18, 2012 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    And you know this how? Because you're certain that you filled the variables? Or because your debugger showed you that they had non-null values in them when the INSERT statement executed. I know I've only been writing software for 40 years, so I don't assume that I don't make mistakes yet, but is it at all possible that your code has a bug?

    Only if you upgraded to a version that doesn't do inserts. If your variables have non-null values, any SQL-based database should insert those values into a new row with your original INSERT statement, unless I'm missing some subtle typo.

    @NetStar:
    I know. :)

    Gotta leave some honeypots on the web though, don't we?
     
    Rukbat, Jun 18, 2012 IP
  8. webshore88

    webshore88 Well-Known Member

    Messages:
    131
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #8
    try this:
    
    $result = mysql_query("INSERT INTO `member`(`user_name`, `bidder_name`, `seller_name`, `user_pass`, `user_email`, `user_ip`) VALUES ('$user_name', '$user_name', '$user_name', '$user_pass', '$user_email', 'user_ip')");        if($result)        {                ///Yippie it's done, now ask that guy to login                header('location: login.php');        }
    PHP:
    I hope it will help you
     
    webshore88, Jun 18, 2012 IP