0

I have a registration script that doesn't work. It used to work but then suddenly it stopped working. I dont know what I've done or what happend. I have tried for like an hour now to find out where the problem is, but I can't seem to find it.

What happens? When I click register I don't get any errors but it doesn't upload to the database:

When I type: $res = mysql_query($query) or die ("ERROR"); it displays ERROR so I think it's related to that code:

//=============Configuring Server and Database=======
$host        =    'localhost';
$user        =    'root';
$password    =    '';
//=============Data Base Information=================
$database    =    'login';

$conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');

//===============End Server Configuration============

//=============Starting Registration Script==========

$username    =    mysql_real_escape_string($_POST['username']);

$password    =    mysql_real_escape_string($_POST['pass1']);

$email    =    mysql_real_escape_string($_POST['email']);

$country    =    mysql_real_escape_string($_POST['country']);

$rights    =    '0';

$IP = $_SERVER['REMOTE_ADDR'];


//=============To Encrypt Password===================

//============New Variable of Password is Now with an Encrypted Value========
$query = mysql_query("SELECT username FROM users WHERE username = '".$username."'"); 
if (mysql_num_rows($query) > 0) 
{ 
    echo 'Username or email already in use.'; 
}
else{
    if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
    {
        $query    =  "insert into users(username,password,email,country,rights,IP,registrated)values('$username','$password','$email','$country',$rights,$IP,NOW())" ;
        $res    =    mysql_query($query);

        header("location:load.php");
    }
}
Marcos Gonzalez
  • 1,086
  • 2
  • 12
  • 19
carl
  • 7
  • 1

2 Answers2

1

Use mysql_error() in order to see what the error message is. If you haven't changed anything in the script then it's either your database structure has changed or your rights have.

Update:

You don't have quotes around your IP value, which is surprising because you said that query worked until now. Anyway you should also consider saving IPs the RIGHT way. Good luck!

Community
  • 1
  • 1
php_nub_qq
  • 15,199
  • 21
  • 74
  • 144
  • Hello. Thanks for replay PHP_nub-qq. it says: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.100.179,NOW())' at line 1 – carl Jun 05 '13 at 13:49
  • ip (probably string) should be quoted. – Bojan Kovacevic Jun 05 '13 at 13:50
  • You don't have quotes around your IP value, which is surprising because you said that query worked until now. Anyway you should also consider saving IPs the [RIGHT way](http://stackoverflow.com/questions/2542011/most-efficient-way-to-store-ip-address-in-mysql). Good luck! – php_nub_qq Jun 05 '13 at 13:53
  • Thanks for the help guys! I found it.. i missed some qoutes -.- – carl Jun 05 '13 at 13:55
1

I think you are getting the error because you are missing some quotes in your query for two columns wich really looks like not integers

'$email','$country',$rights,$IP,NOW())" //$rights and $ip doesn't have quotes 

so your query would look like

"insert into users(username,password,email,country,rights,IP,registrated)values('$username','$password','$email','$country','$rights','$IP',NOW())" 
Fabio
  • 23,183
  • 12
  • 55
  • 64
  • I cant accept until 5 minutts! But hey! Thanks Fabio! :) It worked... i should have seen that -.- but thanks! :) – carl Jun 05 '13 at 13:53