Jump to content


Photo

Small Error - checking username


  • Please log in to reply
2 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 17 August 2006 - 07:01 PM

Here is my register code - I get the data from a form (POST command).

But im getting this error message:

Fatal error: Only variables can be passed by reference in site root here\addnewuser.php on line 18

that being:

end("Username already in use - Try another");

Full script:

<?php

session_start();

$ip = ($_SERVER['HTTP_X_FORWARDED_FOR'])
    ?  $_SERVER['HTTP_X_FORWARDED_FOR']
    :  $_SERVER['REMOTE_ADDR'];

require_once("dbconfig.php");

if($_POST['username'])
{
$username=$_POST['username'];
$username=str_replace(array("<", ">"), array("&lt;", "&gt;"), $username);
$qry=mysql_query("SELECT * FROM users WHERE username='{$username}'",$conn);
if(mysql_num_rows($qry))
{
end("Username already in use - Try another");
}
else if($_POST['password'] != $_POST['verify'])
{
end("The passwords did not match - Try again");
}
else
{
mysql_query("INSERT INTO users (HIDDEN FIELDS) VALUES(HIDDEN VALUES)", $conn);

header("Location: login.php");
}
}
else
{
end("Something went wrong - Try again");
}
?>

Thankd in advance for any help you can give...

#2 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 17 August 2006 - 07:44 PM

Don't know if it will make a different but:
Change:
$qry=mysql_query("SELECT * FROM users WHERE username='{$username}'",$conn);
to
$qry=mysql_query("SELECT * FROM users WHERE username='$username'",$conn);

The Braces are unnecessary.

<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 18 August 2006 - 04:03 PM

You should check mysql_error().
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users