Jump to content

Recommended Posts

Posted

Hello...

I didn't know where it will be the right place where I can start this thread so I started it here "Developer's Corner".

I tried to make an registration page for mangos and it ended up with an error, now I'm blocked and I don't know where is the problem.

<?php
$db_user    = "root"; // MySQL username
$db_pass    = "my_password"; // MySQL password
$db_host    = "localhost"; // MySQL Server Host
$db_db      = "mangos_logon"; // Account database

if($_POST)
{
$con = mysql_connect($db_host,$db_user,$db_pass);
if(!$con)
$msg = "Unable to create a Database connection.";
if($con)
{
mysql_select_db($db_db, $con);
$user = $_POST['login'];
$pass = $_POST['password'];
$email = $_POST['email'];
$pack = $_POST['expansion'];
function sha_password($user,$pass){
$user = strtoupper($user);
$pass = strtoupper($pass);
return SHA1($user.':'.$pass);
}
$sha=sha_password($user,$pass);

if(!$user)
echo "You have not inserted your username.";
else if(!$pass)
echo "You have not inserted your password.";
else if(!$email)
echo "You have not inserted your e-mail";
else
{



$check = mysql_query("SELECT username FROM account WHERE username=\\"".$user."\\" LIMIT 1", $con);
if(mysql_numrows($check) > 0)
echo "Account ".$user." already exists. Please Try Again";
else
{
$query = "INSERT INTO account (username, sha_pass_hash, email, expansion) VALUES
('" . mysql_real_escape_string($user) . "', '" . mysql_real_escape_string($sha) . "', '" . mysql_real_escape_string($email) . "', '" . mysql_real_escape_string($pack) . "');";

if(!mysql_query($query, $con))
echo "Creation of account ".$user." has failed. Please try again later.";
else
echo "Account ".$user." has been created.";
}
}
@mysql_close($con);
}

}

?>

It ends up with this error :

Code Format

echo "Creation of account ".$user." has failed. Please try again later.";

Browser Format

Creation of account test_user has failed. Please try again later.

Posted

Swap out that non-descript error message for something with a little more information, such as:

echo "Query could not complete: " . mysql_error(mysql_errno($sql));

That should tell you -why- the query didn't complete.

[EDIT] my bad, didn't read the code properly. Indentation would've helped... anyway, you have got a database selected, so just do the above and see what happens.

Posted

Try to use more or die (mysql_error()); and you will find your problem!! I did some fixes to your code. Tested and working

<?php
$db_user    = "root"; // MySQL username
$db_pass    = "protroad975"; // MySQL password
$db_host    = "localhost"; // MySQL Server Host
$db_db      = "realmd"; // Account database

if(isset($_POST['submit']))
{
$con = mysql_connect($db_host,$db_user,$db_pass) or die('Could not connect: ' . mysql_error());
mysql_select_db($db_db, $con);
$user = $_POST['login'];
$pass = $_POST['password'];
$email = $_POST['email'];
$pack = $_POST['expansion'];
function sha_password($user,$pass)
{
	$user = strtoupper($user);
	$pass = strtoupper($pass);
	return SHA1($user.':'.$pass);
}
$sha=sha_password($user,$pass);
if(!$user)
	echo "You have not inserted your username.";
else if(!$pass)
	echo "You have not inserted your password.";
else if(!$email)
	echo "You have not inserted your e-mail";
else
{
	$check = mysql_query("SELECT `username` FROM `account` WHERE `username`='".$user."' ", $con)  or die (mysql_error());
	if(mysql_numrows($check) > 0)
		echo "Account ".$user." already exists. Please Try Again";
	else
	{
		$query = "INSERT INTO `account`(`username`, `sha_pass_hash`, `email`, `expansion`) VALUES
('" . mysql_real_escape_string($user) . "', '" . mysql_real_escape_string($sha) . "', '" . mysql_real_escape_string($email) . "', '" . mysql_real_escape_string($pack) . "')";
		$do_query = mysql_query($query) or die (mysql_error());
		if(!mysql_query($do_query))
			echo "Account ".$user." has been created.";
		else
			echo "Creation of account ".$user." has failed. Please try again later.";
	}
}
@mysql_close($con);
}
?>

But you need to add more checks (for email, for username/password length, etc)

×
×
  • Create New...

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. Privacy Policy Terms of Use