Jump to content

Register.php is not running right.


lalonde4

Recommended Posts

Ok so I cant get the register page to insert the information into my database the config file is linked it works but just inserting the info just doesnt work.

 

<?php $title = "Productions - Register";?>
<?php require("styles/top.php"); ?>
<div id='full'>
    <?php

$form = "<form action='register.php' method='post'>
<table>
<tr>
	<td>First Name:</td>
	<td><input type='text' name='firstname'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Last Name:</td>
	<td><input type='text' name='lastname'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Username:</td>
	<td><input type='text' name='username'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Email:</td>
	<td><input type='text' name='email'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Password:</td>
	<td><input type='password' name='password'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Confirm Password:</td>
	<td><input type='password' name='repassword'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Avatar:</td>
	<td><input type='file' name='avatar'></td>
</tr>
<tr>
	<td>Bio/About Me:</td>
	<td><textarea name='bio' cols='35' rows='5'></textarea></td>
</tr>
<tr>
	<td>Website:</td>
	<td><input type='text' name='website'></td>
</tr>
<tr>
	<td>Youtube:</td>
	<td><input type='text' name='youtube'></td>
</tr>
<tr>
	<td>Facebook:</td>
	<td><input type='text' name='facebook'></td>
</tr>
<tr>
	<td>Twitter:</td>
	<td><input type='text' name='twitter'></td>
</tr>
<tr>
	<td></td>
	<td><input type='submit' name='submitbtn' value='Register'></td>
</tr>
<tr>
	<td></td>
	<td><font color='red'>*</font> = Required</td>
</tr>
</table>
</form>";

if ($_POST['submitbtn']){

		$firstname = strip_tags($_POST['firstname']);
		$lastname = strip_tags($_POST['lastname']);
		$username = strip_tags($_POST['username']);
		$email = strip_tags($_POST['email']);
		$password = strip_tags($_POST['password']);
		$repassword = strip_tags($_POST['repassword']);
		$bio = strip_tags($_POST['bio']);
		$website = strip_tags($_POST['webite']);
		$youtube = strip_tags($_POST['youtube']);
		$facebook = strip_tags($_POST['facebook']);
		$twitter = strip_tags($_POST['twitter']);

		$name = $_FILES['avatar']['name'];
		$type = $_FILES['avatar']['type'];
		$size = $_FILES['avatar']['size'];
		$tmpname = $_FILES['avatar']['tmp_name'];
		$ext = substr($name, strrpos($name, '.'));

		if ($firstname && $lastname && $username && $email && $password){
			if ($password == $repassword){

				if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >=6)){

					require("scripts/config.php");

					$query = mysql_query("SELECT * FROM user WHERE username='$username'");$numrows = mysql_num_rows($query);
					if ($numrows == 0){
						$query = mysql_query("SELECT * FROM users WHERE email='$email'");$numrows = mysql_num_rows($query);
					if ($numrows == 0){

						$pass = md5($password);
						$date = date("F d, Y");

						if ($name){
							move_uploaded_file($tmpname, "avatars/$username.$ext");
						}
						else
							$avatar = "defav.png";

						$code = substr(md5(rand(111111111111, 999999999999)), 2,25);

						mysql_query("INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')");

						$webmaster = "[email protected]";
						$subject = "Activation Email";
						$headers = "From: AAG GoD<$webmaster>";
						$message = "Hello $username! Thank you for registering! Below is your activation link.\n\n You must click this link in order to log in. http://www.aagaming.net/productions/activate.php?code=$code";

						mail($email, $subject, $message, $headers);

						echo "Your activation email has been sent to <b>$email</b>. There you will follow a link in order to login. You must complete the activation proccess in order to login. If you run into any problems please email the site administrators. Send an email to <a href='mailto:[email protected]'>[email protected]</a>";

					}
					else
						echo"That email is already in use. $form";

					}
					else
						echo"That username is already in use. $form";


				}
				else
					echo "You did not enter a valid email. $form";
			}
			else
				echo "Your passwords did not match. $form";
		}
		else
			echo "You did not fill out all the required fields. $form";
}
else
	echo "$form";

    ?>
</div>
<?php require("styles/bottom.php"); ?>

Link to comment
https://forums.phpfreaks.com/topic/263297-registerphp-is-not-running-right/
Share on other sites

New code but still wont post into database

 

 

<?php $title = "Productions - Register";?>
<?php require("styles/top.php"); ?>
<div id='full'>
    <?php

$form = "<form action='register.php' method='post'>
<table>
<tr>
	<td>First Name:</td>
	<td><input type='text' name='firstname'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Last Name:</td>
	<td><input type='text' name='lastname'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Username:</td>
	<td><input type='text' name='username'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Email:</td>
	<td><input type='text' name='email'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Password:</td>
	<td><input type='password' name='password'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Confirm Password:</td>
	<td><input type='password' name='repassword'><font color='red'>*</font></td>
</tr>
<tr>
	<td>Avatar:</td>
	<td><input type='file' name='avatar'></td>
</tr>
<tr>
	<td>Bio/About Me:</td>
	<td><textarea name='bio' cols='35' rows='5'></textarea></td>
</tr>
<tr>
	<td>Website:</td>
	<td><input type='text' name='website'></td>
</tr>
<tr>
	<td>Youtube:</td>
	<td><input type='text' name='youtube'></td>
</tr>
<tr>
	<td>Facebook:</td>
	<td><input type='text' name='facebook'></td>
</tr>
<tr>
	<td>Twitter:</td>
	<td><input type='text' name='twitter'></td>
</tr>
<tr>
	<td></td>
	<td><input type='submit' name='submitbtn' value='Register'></td>
</tr>
<tr>
	<td></td>
	<td><font color='red'>*</font> = Required</td>
</tr>
</table>
</form>";

if ($_POST['submitbtn']){

		$firstname = strip_tags($_POST['firstname']);
		$lastname = strip_tags($_POST['lastname']);
		$username = strip_tags($_POST['username']);
		$email = strip_tags($_POST['email']);
		$password = strip_tags($_POST['password']);
		$repassword = strip_tags($_POST['repassword']);
		$bio = strip_tags($_POST['bio']);
		$website = strip_tags($_POST['webite']);
		$youtube = strip_tags($_POST['youtube']);
		$facebook = strip_tags($_POST['facebook']);
		$twitter = strip_tags($_POST['twitter']);

		$name = $_FILES['avatar']['name'];
		$type = $_FILES['avatar']['type'];
		$size = $_FILES['avatar']['size'];
		$tmpname = $_FILES['avatar']['tmp_name'];
		$ext = substr($name, strrpos($name, '.'));

		if ($firstname && $lastname && $username && $email && $password){
			if ($password == $repassword){

				if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >=6)){

					require("scripts/config.php");

					$query = mysql_query("SELECT * FROM user WHERE username='$username'");
                                                $numrows = mysql_num_rows($query);
					if ($numrows == 0){
						$query = mysql_query("SELECT * FROM users WHERE email='$email'");
                                                        $numrows = mysql_num_rows($query);
					if ($numrows == 0){

						$pass = md5($password);
						$date = date("F d, Y");

						if ($name){
							move_uploaded_file($tmpname, "avatars/$username.$ext");
						}
						else
							$avatar = "defav.png";

						$code = substr(md5(rand(111111111111, 999999999999)), 2,25);

						mysql_query("INSERT INTO users VALUES('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')")

						or die(mysql_error());



						$webmaster = "[email protected]";
						$subject = "Activation Email";
						$headers = "From: AAG GoD<$webmaster>";
						$message = "Hello $username! Thank you for registering! Below is your activation link.\n\n You must click this link in order to log in. http://www.aagaming.net/productions/activate.php?code=$code";

						mail($email, $subject, $message, $headers);

						echo "Your activation email has been sent to <b>$email</b>. There you will follow a link in order to login. You must complete the activation proccess in order to login. If you run into any problems please email the site administrators. Send an email to <a href='mailto:[email protected]'>[email protected]</a>";

					}
					else
						echo"That email is already in use. $form";

					}
					else
						echo"That username is already in use. $form";


				}
				else
					echo "You did not enter a valid email. $form";
			}
			else
				echo "Your passwords did not match. $form";
		}
		else
			echo "You did not fill out all the required fields. $form";
}
else
	echo "$form";

    ?>
</div>
<?php require("styles/bottom.php"); ?>

Your queries are failing. You need to check that the queries succeed - if not, check what the error is. On all your queries you should define the query as a string variable and then run that in mysql_query. That way, if the query fails, you can eche the que5ry and the error to the page.

$query = "SELECT * FROM user WHERE username='$username'";
$result = mysql_query($query) or die("Query: $query<br>Error: " . mysql_error());

 

Do that on all the queries you run.

 

 

Nope that didnt work its still failing.

 

Of course it is still failing! That code will not fix the error, but it will show you what the error IS. We can't help you because we don't know what the problem is. If you cannot implement simple debugging steps and ascertain the results for us to review then there isn't much we can do to help you.

try this:

$sql = "INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')";

echo $sql;

mysql_query($sql) or die(mysql_error());

     

Then take the query that prints to your screen and try running it in phpmyadmin directly to see the error you get there.

 

My guess is your columns don't match up.

 

You should never do an insert without specifying the columns.... if you ever add columns to your table, you'll break the query.

 

It should be like this:

 

INSERT INTO table_name (col1, col2) VALUES ('data1', 'data2');

I mean like that doesnt display any errors either thats my problem I am doing simple debugging strategies but its showing nothing.

 

Then start at the beginning. Have you even verified that the page you *think* is running is the one that is actually running? At teh very start of the page do something like this

echo "Start debugging<br>";

 

Then at the very first control you could do something like this

if ($_POST['submitbtn']){
echo "POST[submitbtn] = TRUE<br>";

 

Also, add a debug statement for the false condition. By the way, you should rethink how you set up your IF/THEN logic. When you do something such as this

if(NOT ERROR CONDITION 1)
{
    if(NOT ERROR CONDITION 2)
    {
        //perform success condition
    }
    else
    {
        //perform error condition 2
    }
}
else
{
    //perform error condition 1
}

 

It makes it very difficult to manage the conditions with their errors. It is much better to follow a pattern such as this

if(ERROR CONDITION 1)
{
    //perform error condition 1
}
else if(ERROR CONDITION 2)
{
    //perform error condition 2
}
else
{
    //perform success scenario
}

try this:

$sql = "INSERT INTO table_users VALUES ('', '$firstname', '$lastname', '$email', '$pass', '$avatar', '$bio', '$website', '$youtube', '$facebook', '$twitter', '', '0', '$code', '0', '$date')";

echo $sql;

mysql_query($sql) or die(mysql_error());

     

Then take the query that prints to your screen and try running it in phpmyadmin directly to see the error you get there.

 

My guess is your columns don't match up.

 

You should never do an insert without specifying the columns.... if you ever add columns to your table, you'll break the query.

 

It should be like this:

 

INSERT INTO table_name (col1, col2) VALUES ('data1', 'data2');

 

This is the error i get with this try

 

INSERT INTO users VALUES ('', 'Matt', 'Lalonde', '[email protected]', 'b8955b3dda83d2aa5c07c00e86229f85', 'defav.png', '', '', '', '', '', '', '0', 'c6f1a668129cbeb2a52f2edfc', '0', 'May 29, 2012')Column count doesn't match value count at row 1

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.