0
$dbHost = "localhost"; 
$dbUsr = "root"; 
$dbPass = "";

function register() { 
  $username = md5($_POST['username']); 
  $password = md5($_POST['password']); 
  $remote = md5($_SERVER['REMOTE_ADDR']);

  $connect = mysql_connect("$dbHost", "$dbUsr", "$dbPass");
  mysql_select_db("drupia1", $connect);

  $query = sprintf('INSERT INTO usrs
                      (username, password, ip)
                    VALUES
                      ("$username", "$password", "$remote"', mysql_real_escape_string($username), mysql_real_escape_string($password));
}

Why is it this script and any other way I write it, the values in mysql seem to be 0?

3
  • 1
    because you're using sprintf in a wrong way. Commented May 4, 2011 at 3:23
  • U need %s instead of the variables Commented May 4, 2011 at 3:25
  • @ianace: The edit you propose corrects the issue/error the OP has -- your correction doesn't help the OP. Commented May 4, 2011 at 3:28

1 Answer 1

3

Consult php.net for using sprintf - it should resemble:

$query = sprintf("INSERT INTO usrs 
                    (username, password, ip) 
                  VALUES
                    ('%s', '%s', '%s' )", 
                  mysql_real_escape_string($username), 
                  mysql_real_escape_string($password),
                  $remote); 
Sign up to request clarification or add additional context in comments.

2 Comments

this is still missing the third %s which, presumably, is supposed to be remote.
no it is ok now, you made correct changes it was the single quotes, Thanks @OMG

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.