Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

Small Error - checking username

Recommended Posts

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

But im getting this error message:

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

that being:

[code]
end("Username already in use - Try another");
[/code]

Full script:

[code]
<?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");
}
?>
[/code]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You should check mysql_error().

Share this post


Link to post
Share on other sites

×

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.