Jump to content

[SOLVED] A few questions about this sign up script that won't work...


bobleny

Recommended Posts

Going on the assumption, do to my inexperience with MySQL, that "!$rows" = "$rows = 0", I have changed the script a bit more.

 

Latest version, yet again:

<?php
if(isset($_POST['sign_username']) == TRUE)
{
$connect = mysql_connect($database_hostname, $database_username, $database_password);
if(!$connect)
{
	$_SESSION['error_message'] = mysql_error();
	$_SESSION['error_location'] = "Line: 106";
	mysql_close();
	sendem(error, .1);
	die();
}

$selectdb = mysql_select_db("testy");
if(!$selectdb)
{
	$_SESSION['error_message'] = mysql_error();
	$_SESSION['error_location'] = "Line: 116";
	mysql_close();
	sendem(error, .1);
	die();
}

$query = mysql_query("SELECT `name` FROM `users` WHERE `name`='{$_POST['sign_username']}'");
if(!$query)
{
	$_SESSION['error_message'] = mysql_error();
	$_SESSION['error_location'] = "Line: 126";
	mysql_close();
	sendem(error, .1);
	die();
}

$rows = mysql_num_rows($query);
if(!$rows)
{
	if($_POST['sign_password'] == $_POST['sign_varpassword'])
	{
		$md5 = md5($_POST['sign_password']);
		$sign_password = SHA1($md5);
		$sign_username = $_POST['sign_username'];
		$sign_lvl = "Super Noob";
		$sign_date = date('l, F jS\, Y');

		$query = mysql_query("INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'");
		if(!$query)
		{
			$_SESSION['error_message'] = mysql_error();
			$_SESSION['error_location'] = "Line: 156";
			mysql_close();
			sendem(error, .1);
			die();
		}
		else
		{
			mysql_close();
			$_SESSION['now_sign'] = TRUE;
			sendem(signup, .1);
		}
	}
	else
	{
		$_SESSION['wrong_sign_password'] = TRUE;
		sendem(signup, .1);
	}
}
else
{
	$_SESSION['wrong_sign_username'] = TRUE;
	sendem(signup, .1);
}
}
?>

 

My new error:

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 '' at line 1

 

My script returned "Line: 156" which is this statement:

<?php
$query = mysql_query("INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'");
if(!$query)
{
$_SESSION['error_message'] = mysql_error();
$_SESSION['error_location'] = "Line: 156";
mysql_close();
sendem(error, .1);
die();
}
else
{
mysql_close();
$_SESSION['now_sign'] = TRUE;
sendem(signup, .1);
}
?>

Access denied for user 'www-data'@'localhost' (using password: NO)

that means that the user was denied access to the database are you including the config.php or whatever file connects to the database and is it right.

On line 156 we're going to take a look at the query that is actually run: edit->cut the part in quotes and set $sql right before the query to that value. Then change the query to mysql_query($sql). Right between the query and $sql, let's do die($sql) and see what it shows us.

Change

$query = mysql_query("INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'");

 

to this

 

$sql = "INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'";
die($sql);
$query = mysql_query($sql);

 

Run it, it should give you the sql statement. See if everything looks right there. If not, fix it and take out the die($sql) line and the query will run again.

Wow! That worked! How cool!

 

Thanks!!!

 

I don't understand though...

 

whats the difference between this:

<?php
$sql = "INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'";
$query = mysql_query($sql);
?>

 

and this?:

<?php
$query = mysql_query(INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}');

 

Thanks to everyone! :D

Yes all is good, however, after I got it to work with this:

<?php
$sql = "INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}'";
$query = mysql_query($sql);
?>

 

I tried this:

<?php
$query = mysql_query(INSERT INTO `users` (`name`, `password`, `level`, `signup`) VALUES ('{$sign_username}','{$sign_password}','{$sign_level}','{$sign_date}');

 

I got the syntax error again...

 

However, it does work and I appreciate your help!

Archived

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

×
×
  • 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.