Registration Problems

data not being added to my table

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1232 Views - Last Post: 04 January 2011 - 02:49 PM Rate Topic: -----

#1 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Registration Problems

Posted 02 January 2011 - 08:45 PM

i have registration for my site heres the html for the form

					<div id='login-form' style='margin:auto;width:100%;margin-top:'>

						<form onsubmit="return Validate()"; action="registration_data.php" method="post" name="registration_form">
						<p>Username: <input style="border:1px solid #fff;min-height:25px;margin-top:5px;margin-bottom:5px;-moz-border-radius: 8px;-webkit-border-radius: 8px;padding:5px;" type="text" name="username"/></p>
						<p>Password: <input style="border:1px solid #fff;min-height:25px;margin-top:5px;margin-bottom:5px;-moz-border-radius: 8px;-webkit-border-radius: 8px;padding:5px;" type="password" name="password"/></p>
						<p>Confirm: <input style="border:1px solid #fff;min-height:25px;margin-top:5px;margin-bottom:5px;-moz-border-radius: 8px;-webkit-border-radius: 8px;padding:5px;" type="password" name="passconf"/></p>
						<p>Name: <input style="border:1px solid #fff;min-height:25px;margin-top:5px;margin-bottom:5px;-moz-border-radius: 8px;-webkit-border-radius: 8px;padding:5px;" type="text" name="name"/></p>
						<p>Email: <input style="border:1px solid #fff;min-height:25px;margin-top:5px;margin-bottom:5px;-moz-border-radius: 8px;-webkit-border-radius: 8px;padding:5px;" type="text" name="email"/></p>
						<p><input style="border:1px solid #fff;min-height:25px;margin-top:5px;margin-bottom:5px;-moz-border-radius: 8px;-webkit-border-radius: 8px;padding:5px;"type="submit" value="Register" /></p>
					</form>



My problem is the users data is not being added to my table in my database and im not sure if its because of my form or my PHP

heres my registration_data.php file

<?php

session_start();

// form data
$submit = $_POST['submit'];

$name = strip_tags($_POST['name']);
$username = strip_tags($_POST['username']);

$password = strip_tags($_POST['password']);
$passconf = strip_tags($_POST['passconf']);

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


if ($submit)
{
	//Connect to database
	include_once "connection.php";
	
	$namecheck = mysql_query("SELECT `username` && `email` FROM `carbonstudios` WHERE `username` = '$username' && `email` = '$email'");
	$count = mysql_num_rows($namecheck);
	
	if($count != 0)
	{
		die("Username is already taken!");
	}
	if($name && $username && $password && $passconf && $email)
	{
		
		if(strlen($username) > 32 || strlen($username) < 4 || strlen($name) > 64 ||  strlen($name) < 3 || strlen($email) > 255 || strlen($email) < 10)
		{
			echo "The length of your username, name, or email are either to long or to short!";
		}else{
		
			// check password length
			if(strlen($password) > 20 || strlen($password) < 6)
			{
				echo "Password must be between 6 and 20 characters!";
			}else{
				
				// register the user
				
				// encrypt password
				$password = md5($password);
				$passconf = md5($passconf);

				$queryreg = mysql_query("INSERT INTO `carbonstudios` (id, username, password, name, email, admin)VALUES ('','$username','$password','$name','$email','0')");
echo "Registration Complete";
header('Location: ./index.php');
						
					}

			}

	
	}

}

?>


and heres my connection file

<?php

    $conn = mysql_connect("localhost", "root", "") or die("Could Not Connect");
    mysql_select_db("users") or die("Could Not find Database");

?>

any help would be greatly appreciated this issue is very frustrating



Is This A Good Question/Topic? 0
  • +

Replies To: Registration Problems

#2 garfinkle  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 87
  • Joined: 08-September 09

Re: Registration Problems

Posted 02 January 2011 - 08:51 PM

At what point is $_POST['submit'] set?

I may be missing this I'm trying to read this on my iphone and the formatting of the code blocks doesn't work too well with the DIC Lo-Fi theme

Matt
Was This Post Helpful? 0
  • +
  • -

#3 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Registration Problems

Posted 02 January 2011 - 08:58 PM

View Postgarfinkle, on 02 January 2011 - 07:51 PM, said:

At what point is $_POST['submit'] set?

I may be missing this I'm trying to read this on my iphone and the formatting of the code blocks doesn't work too well with the DIC Lo-Fi theme

Matt


Its right after session start on the registration_data.php file i posted
Was This Post Helpful? 0
  • +
  • -

#4 garfinkle  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 87
  • Joined: 08-September 09

Re: Registration Problems

Posted 02 January 2011 - 08:59 PM

Try changing

	$queryreg = mysql_query("INSERT INTO `carbonstudios` (id, username, password, name, email, admin)VALUES ('','$username','$password','$name','$email','0')");



to

	$queryreg = mysql_query("INSERT INTO `carbonstudios` (username, password, name, email, admin)VALUES ('$username','$password','$name','$email','0')");



assuming your ID field is an auto incremented integer then setting it to '' will fail as it is an invalid type. Only set the fields that you have values for.

Hope this fixes it

Matt

P.S. I found the submit :)
Was This Post Helpful? 0
  • +
  • -

#5 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Registration Problems

Posted 02 January 2011 - 09:17 PM

View Postgarfinkle, on 02 January 2011 - 07:59 PM, said:

Try changing

	$queryreg = mysql_query("INSERT INTO `carbonstudios` (id, username, password, name, email, admin)VALUES ('','$username','$password','$name','$email','0')");



to

	$queryreg = mysql_query("INSERT INTO `carbonstudios` (username, password, name, email, admin)VALUES ('$username','$password','$name','$email','0')");



assuming your ID field is an auto incremented integer then setting it to '' will fail as it is an invalid type. Only set the fields that you have values for.

Hope this fixes it

Matt

P.S. I found the submit :)


Thanks for the try but that didnt work i know it must be something im not doing write because my PHP isnt even echoing the Registration complete message
Was This Post Helpful? 0
  • +
  • -

#6 garfinkle  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 87
  • Joined: 08-September 09

Re: Registration Problems

Posted 02 January 2011 - 09:28 PM

At the top of your registration data file put the following

echo '<pre>';
print_r($_POST);
echo '</pre>';



That will output a formatted array of all post data.

Ensure that all values are being passed correctly and ensure that submit is also set.


A safer than

if($submit)



Would be

if(isset($_POST['submit']))



Checking if a variable is set is safet than doing a Boolean variable check on a string value.

If you put an echo statemtb before each section of you registration script. What is the last echo that I successfully printed to the screen?


Matt

P.S. Sorry for any typos , half 4 in the morning and iPhone autocorrect Is a bad thing :)

This post has been edited by garfinkle: 02 January 2011 - 09:29 PM

Was This Post Helpful? 1
  • +
  • -

#7 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Registration Problems

Posted 02 January 2011 - 09:37 PM

View Postgarfinkle, on 02 January 2011 - 08:28 PM, said:

At the top of your registration data file put the following

echo '<pre>';
print_r($_POST);
echo '</pre>';



That will output a formatted array of all post data.

Ensure that all values are being passed correctly and ensure that submit is also set.


A safer than

if($submit)



Would be

if(isset($_POST['submit']))



Checking if a variable is set is safet than doing a Boolean variable check on a string value.

If you put an echo statemtb before each section of you registration script. What is the last echo that I successfully printed to the screen?


Matt

P.S. Sorry for any typos , half 4 in the morning and iPhone autocorrect Is a bad thing :)


:/ it still isnt working i think it most likely is the form because the actual registration script itself worked perfectly before on a previous version of the site.

:gun_bandana: Ipod Auto complete feature

:D
Was This Post Helpful? 0
  • +
  • -

#8 garfinkle  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 87
  • Joined: 08-September 09

Re: Registration Problems

Posted 02 January 2011 - 09:40 PM

You have a syntax error in your form tag.

There is a semi colon after the onsubmit parameter. Should be inside the quotations

:)

This post has been edited by garfinkle: 02 January 2011 - 09:42 PM

Was This Post Helpful? 1
  • +
  • -

#9 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Registration Problems

Posted 02 January 2011 - 09:57 PM

View Postgarfinkle, on 02 January 2011 - 08:40 PM, said:

You have a syntax error in your form tag.

There is a semi colon after the onsubmit parameter. Should be inside the quotations

:)


Thanks for checking that but its still not working i have no idea whats wrong with it D: if it works it should display the echo Registration complete but its not.
Was This Post Helpful? 0
  • +
  • -

#10 garfinkle  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 87
  • Joined: 08-September 09

Re: Registration Problems

Posted 02 January 2011 - 10:10 PM

The only other thing that I can see that may be causing an issue is on you insert statement

You have no space between the ) and the VALUES keyword.

If that isn't the issue the only thing I can recommend is try that bit of code to output the post data. Ensure that all data is getting to your registration form correctly (before it is processed). If the post array is empty, then your HTML form is failing. If the array is fine then the issue is your php.

Also update all your mysql queries so that they run as

$SQL = "SQL STATEMENT";
$query = mysql_query($SQL) or die("Error: " . mysql_error() . "<br /> trying to parse SQL: " . $SQL);



This will catch any SQL errors that may be occurring.

Try to work out what parts run successfully and what parts fail. This should allow you to track exactly where the error is.

I'm off to get some sleep now.

Hope you track the error down and if not I'll see if I can spot anything else when I'm back at my computer tomorrow.

Matt

This post has been edited by garfinkle: 02 January 2011 - 10:11 PM

Was This Post Helpful? 0
  • +
  • -

#11 JamesRozee  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 26
  • Joined: 01-January 11

Re: Registration Problems

Posted 03 January 2011 - 08:00 AM

Below is a basic form, as I do not want to do your homework for you its an example you can build on.

You've made some careless mistakes, for example your submit button is the first problem, you call for $_POST[ 'submit' ], but the HTML form has no existence of "submit" (fix: on the submit button add name="submit"), so the first if statement returns false.

Check the form, it should give you an easier understanding.

Read more on this too: function isset(...)


<form action="" method="post">
    <p>
        Username: <input type="text" name="username" />
    </p>
    
    <p>
        Password: <input type="password" name="password" />
    </p>
    
    <p>
        <input type="submit" name="submit" value="Go" />
    </p>
</form>

<?php
// Strip tags if you want this is just an example

$username = $_POST[ 'username' ];
$password = $_POST[ 'password' ];

if( isset( $_POST[ 'submit' ] ) )
{
    if( $username == '' )
    {
        echo 'You havent provided a username'; exit;
    }
    
    if( $password == '' )
    {
        echo 'You havent provided a password'; exit;
    }
    
    /* Do some more checks 
    
    if(...) */
    
    // Query Database
    
    // Get Result
    
    // Display + Do something

}
else
{
    // No acknowledgement of the submit button being pressed.

}

?>



Was This Post Helpful? 0
  • +
  • -

#12 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Registration Problems

Posted 03 January 2011 - 09:15 AM

Thanks for the help but you dont need to say your dont want to do my homework for me as i dont even goto school for this stuff im teaching myself i am 15....

This post has been edited by JackOfAllTrades: 04 January 2011 - 01:15 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#13 JamesRozee  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 26
  • Joined: 01-January 11

Re: Registration Problems

Posted 03 January 2011 - 09:25 AM

Quote

Thanks for the help but you dont need to say your dont want to do my homework for me as i dont even goto school for this stuff im teaching myself i am 15....


I didn't intend for it to mean your work that you do at school.

I can easily correct your code, and you will copy and paste it and everything be hunky-doory but then you've learnt nothing.

"Give an person some code and they'll be set for a day, teach a person to code and they'll be set for life."

This post has been edited by Dormilich: 04 January 2011 - 04:30 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 1
  • +
  • -

#14 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Registration Problems

Posted 03 January 2011 - 11:04 AM

Ok i just wanted to make that clear cause i know people that actually do post there work for school on here get bad per for it... :)

This post has been edited by JackOfAllTrades: 04 January 2011 - 01:15 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#15 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,517
  • Joined: 23-August 08

Re: Registration Problems

Posted 03 January 2011 - 11:05 AM

View PostJamesRozee, on 03 January 2011 - 10:25 AM, said:

I didn't intend for it to mean your work that you do at school.

I can easily correct your code, and you will copy and paste it and everything be hunky-doory but then you've learnt nothing.

"Give an person some code and they'll be set for a day, teach a person to code and they'll be set for life."


Welcome aboard, JamesRozee! I see you'll fit in very well here! :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2