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);
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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