Having problem with php/mysel register

I am having trouble with my register form, it doesn’t seam to be inputting the data into my database.

Here is the HTML page:

[code]

WoW Luck - Create Account

Welcome to WoWLuck.com!


WoW just got better.

Latest Jackpot Winners

10,000G Winner
Bigwork of The Forgotten Coast

 

 

 

 

 

 

 

Contact




Username *
Password *
Confirm Password *
Character Name
Realm Name
E-mail *

* = Required

 

Visa Master Card Discover PayPal
©2010 WoW Luck. ALL RIGHTS RESERVED

[/code]

Here is the php page:

[php]<?
/* This code will make a connection with database */
$con=mysql_connect(“localhost”,“root”,“password”);

/* Now, we select the database */
mysql_select_db(“mmoluck”);

/* Now we will store the values submitted by form in variable */
$username=$_POST[‘username’];
$pass=$_POST[‘password’];
$char=$_POST[‘character’];
$realm=$_POST[‘realm’];
$email=$_POST[‘email’];

/* we are now encrypting password while using md5() function */
$password=md5($pass);
$confirm_password=$_POST[‘confirm_password’];
$confirm_email=$_POST[‘confirm_email’]:

/* Now we will check if username is already in use or not */
$queryuser=mysql_query("SELECT * FROM accounts WHERE username=’$username’ ");
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)
{ echo “Sorry, “.$username.” is already been taken.”; }
else {

$queryuser=mysql_query("SELECT * FROM email WHERE email=’$email’ ");
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)
{ echo “Sorry, “.$email.” is already being used.”; }
else {

/* now we will check if password and confirm password matched */
if($pass != $confirm_password)
{ echo “Password and confirm password fields were not matched”; }
else {

if($email != $confrim_email)
{ echo “E-mail and confirm e-mail fields were not matched”; }
else {

/* Now we will write a query to insert user details into database */
$insert_user=mysql_query(“INSERT INTO accounts (username, password, character, realm, email) VALUES (’$username’, ‘$password’ ‘$character’, ‘$realm’, ‘$email’)”);

if($insert_user)
{ echo “Registration Succesfull”; }
else
{ echo “error in registration”.mysql_error(); }

/* closing the if else statements */
}}

mysql_close($con);
?>[/php]

Hi!

What output do you get from the PHP script?

One thing I have noticed is you made a typo on line

[php]if($email != $confrim_email)[/php]

so I think you always get the “E-mail and confirm e-mail fields were not matched”, therefore the script never reaches the INSERT statement.

Correct this and let us know if you still have the same problem.

PS: look into sanitizing user input; if you’re not doing it, your website is vulnerable to SQL Injections and XSS (google these, i’m sure you will find lots of info)

Cheers!

Aye! I just noticed that I didn’t have confirm e-mail in my html form so I completely removed it from the php script but I still get a blank page when I click submit and no data is sent to my database.

Thanks.

I found one more error - below line had a colon at the end instead of a semicolon (i understand it has not been removed?)

$confirm_email=$_POST[‘confirm_email’]:

However on closer inspection, the curly brackets are not nested properly. After line

/* closing the if else statements */

you had 2 closing brackets, whereas you should have had 4 of them.

I tried to correct the script for you (removed the email confirm too)

[php]

<? /* This code will make a connection with database */ $con=mysql_connect("localhost","root","password"); /* Now, we select the database */ mysql_select_db("mmoluck"); /* Now we will store the values submitted by form in variable */ $username=$_POST['username']; $pass=$_POST['password']; $char=$_POST['character']; $realm=$_POST['realm']; $email=$_POST['email']; /* we are now encrypting password while using md5() function */ $password=md5($pass); $confirm_password=$_POST['confirm_password']; /* Now we will check if username is already in use or not */ $queryuser=mysql_query("SELECT * FROM accounts WHERE username='$username' "); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { echo "Sorry, ".$username." is already been taken."; } else { $queryuser=mysql_query("SELECT * FROM email WHERE email='$email' "); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { echo "Sorry, ".$email." is already being used."; } else { /* now we will check if password and confirm password matched */ if($pass != $confirm_password) { echo "Password and confirm password fields were not matched"; } else { /* Now we will write a query to insert user details into database */ $insert_user=mysql_query("INSERT INTO accounts (username, password, character, realm, email) VALUES ('$username', '$password' '$character', '$realm', '$email')"); if($insert_user) { echo "Registration Succesfull"; } else { echo "error in registration".mysql_error(); } /* closing the if else statements */ } } } mysql_close($con); ?>

[/php]

However before you try this one, add the following line at the top of the original php file and try running it again; if should now tell you what errors you have.

[php]error_reporting(E_ALL)[/php]

I suggest you find your php.ini for your development environment and change error_reporting to “error_reporting = E_ALL | E_STRICT” (without the quotes) -this will help you correct errors in your scripts.

Good luck!

Alright so I have made all the changes that you said including the ones to the php.ini file and still nothing =[ would it help if I sent you the address to my page?

Sponsor our Newsletter | Privacy Policy | Terms of Service