Jump to content


Photo

MySQL User Registration Problem


  • Please log in to reply
32 replies to this topic

#1 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 14 December 2006 - 11:17 PM

I have my database and HTML forms made. When I click submit to submit the registration it doesnt go to to the database it comes to a page with all of my database stuff on it. Can someone help? I have the page register.html made with the forms on it. When you click on submit its supposed to go to register.php which will send the info to the database. But is doesnt. Here is the register.php code:

//Database Information 

$dbhost = "localhost"; 
$dbname = "users"; 
$dbuser = "MY USERNAME"; 
$dbpass = "MY PASSWORD"; 

//Connect to database 

mysql_connect ($localhost, $MY USERNAME, $MY PASSWORD)or die("Could not connect: ".mysql_error()); 
mysql_select_db($users) or die(mysql_error()); 

$firstname = $_POST['firstname']; 
$username = $_POST[username']; 
$password = md5($_POST['password']); 
$email = $_POST['email']; 
$gamertag = $_POST['gamertag']; 
$gender = $_POST['gender']; 

// lets check to see if the username already exists 

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); 

$username_exist = mysql_num_rows($checkuser); 

if($username_exist > 0){ 
echo "I'm sorry but the username you specified has already been taken. Please pick another one."; 
unset($username); 
include 'register.html'; 
exit(); 
} 

// lf no errors present with the username 
// use a query to insert the data into the database. 

$query = "INSERT INTO users (firstname, username, password, email, gamertag, gender) 
VALUES('$firstname', '$username', '$password', '$email', '$gamertag', '$gender')"; 
mysql_query($query) or die(mysql_error()); 
mysql_close(); 

echo "You have successfully Registered"; 

// mail user their information 

$yoursite = ‘LeThaL Gaming’; 
$webmaster = ‘Sal (LeThaL P1STONS)’; 
$youremail = ‘[email protected]’; 

$subject = "You have successfully registered at $yoursite..."; 
$message = "Dear $name, you are now registered at our web site. 
To login, simply go to our web page and enter in the following details in the login form: 
Username: $username 
Password: $password 

Please print this information out and store it for future reference. 

Thanks, 
$Sal"; 

mail($email, $subject, $message, "From: $LeThaL Gaming <$[email protected]>\nX-Mailer:PHP/" . phpversion()); 

echo "Your information has been mailed to your email address."; 

?>

Thanks

Edited by Mr. Matt, 15 December 2006 - 01:48 PM.


#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 15 December 2006 - 01:43 PM

Could you show us the form as well?

#3 Archbob

Archbob

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 15 December 2006 - 03:47 PM

Is it just printing the code instead of executing it.
If it is either PHP is set up wrong or you forgot <?php before the code.

#4 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 15 December 2006 - 04:57 PM

i got it to not print out buy now its comes up with this error:

"Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in /home/www/salman6.100webspace.net/register.php on line 17"

anyone?

Edited by pistonsfreak, 15 December 2006 - 09:35 PM.


#5 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 15 December 2006 - 09:38 PM

Give us a bit of a break pistonfreak...most people are in bed at this time of night.

The problem is this line:
$username = $_POST[username'];

Notice the missing quote mark. Replace it with:
$username = $_POST['username'];


#6 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 16 December 2006 - 12:46 AM

Now it says:

"Parse error: parse error, unexpected '=' in /home/www/lethalgaming.awardspace.com/register.php on line 48"

From what I see there is nothing missing. Thanks

#7 Hayden

Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 717 posts
  • Gender:Male
  • Location:Texas

Posted 16 December 2006 - 02:40 AM

what's up with the tic marks there for the quotes?

$yoursite = ‘LeThaL Gaming’;
$webmaster = ‘Sal (LeThaL P1STONS)’;
$youremail = ‘[email protected]’;

not really sure if it makes any difference but what about...

$yoursite = 'LeThaL Gaming';
$webmaster = 'Sal (LeThaL P1STONS)';
$youremail = '[email protected]';


#8 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 16 December 2006 - 11:22 AM

that fixed that problem but now here another one :) :

"Warning: mysql_connect(): Unknown MySQL Server Host 'awardspacecom' (1) in /home/www/lethalgaming.awardspace.com/register.php on line 12
Could not connect: Unknown MySQL Server Host 'awardspacecom' (1)"

Here is my database info:

"//Database Information

$dbhost = "fdb1.awardspace.com";
$dbname = "lethalgaming_lg_users";
$dbuser = "lethalgaming_lg";
$dbpass = "MY PASSWORD";"

Here is what the host says to put for the MySQL Database info:

"DB Host- fdb1.awardspace.com, Database Name- lethalgaming_lg, DB User- lethalgaming_lg"

Thanks

#9 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 16 December 2006 - 02:43 PM

Are you hosted on that server?
If so, you could just try 'localhost' for your host in the mysql_connect() function.
Usually is the default you should use anyways.

Otherwise, try using a compltet address, with 'http://www.' and such, as in some cases I notice you have to have those in a URL in order for it to work with certain functions.

Edited by Demonslay, 16 December 2006 - 02:45 PM.


#10 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 16 December 2006 - 03:48 PM

looking at the very top code the details do not match:

//Database Information

$dbhost = "localhost";
$dbname = "users";
$dbuser = "MY USERNAME";
$dbpass = "MY PASSWORD";

//Connect to database

mysql_connect ($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

Matt

#11 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 16 December 2006 - 06:40 PM

In the MySQL connect part i put "localhost" instead of "fdb1.awardspace.com" (which is what it says to put) and i get this:

"Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/lethalgaming.awardspace.com/register.php on line 12
Could not connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

Here is what the top says:

"//Database Information

$dbhost = "fdb1.awardspace.com";
$dbname = "lethalgaming_lg_users";
$dbuser = "lethalgaming_lg";
$dbpass = "my password";

//Connect to database

mysql_connect ($localhost, $lethalgaming_lg, $italia)or die("Could not connect: ".mysql_error());
mysql_select_db($lethalgaming_lg__users) or die(mysql_error);"

Edited by pistonsfreak, 16 December 2006 - 06:42 PM.


#12 LkuHomer

LkuHomer

    Young Padawan

  • Members
  • Pip
  • 173 posts
  • Gender:Male
  • Location:Dela'where?

Posted 16 December 2006 - 08:37 PM

mysql_connect ($localhost, $lethalgaming_lg, $italia)or die("Could not connect: ".mysql_error());
mysql_select_db($lethalgaming_lg__users) or die(mysql_error);"


mysql_connect("$dbhost", "$dbuser", "$dbpass")or die();
mysql_select_db($dbname)or die();

You're putting the variable information in the connect, instead of using the variables. If you did that you wouldn't need the '$'

Edited by LkuHomer, 16 December 2006 - 08:40 PM.


#13 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 16 December 2006 - 09:03 PM

OK I kinda figured out how to do the variables and stuff. But I still get an error and this is what it says:
"Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/lethalgaming.awardspace.com/config.php on line 10
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

Heres what config.php says:

"<?PHP

//Database Information
$db[host] = "fdb1.awardspace.com";
$db[user] = "<lethalgaming_lg>";
$db[pass] = "<my password>";
$db[name] = "<lethalgaming_lg_users>";

//Connect To The Database
mysql_connect($db[fdb1.awardspace.com], $db[lethalgaming_lg], $db[my password]) or die(mysql_error());
mysql_select_db($db[lethalgaming_lg_users]);

?>"

Heres what the beginning of register.php says:

"<?PHP

session_start();
ob_start();

//Include the configurations
include('config.php');

//Define a few variables
$x = $_GET['x'];
$u = $_GET['u'];"

Im not sure if for the host I should put "localhost" in because on the Database information on the host it says to put "fdb1.awardspace.com" in.

Thanks for all the help

Edited by pistonsfreak, 16 December 2006 - 09:32 PM.


#14 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 04:24 AM

*sigh*

You need to go back and learn the basics of variables. This is what you are trying to do:

$password = 'mattyg';
echo $mattyg;
/* wil echo nothing */

thats wrong, when you set a value to a variable, if you want to use that value you call the variable:

$password = 'mattyg';
echo $password;
/* Will echo 'mattyg' */

In the latest code you are showing us:

<?PHP

//Database Information
$db[host] = "fdb1.awardspace.com";
$db[user] = "<lethalgaming_lg>";
$db[pass] = "<my password>";
$db[name] = "<lethalgaming_lg_users>";

//Connect To The Database
mysql_connect($db[fdb1.awardspace.com], $db[lethalgaming_lg], $db[my password]) or die(mysql_error());
mysql_select_db($db[lethalgaming_lg_users]);

?>

Youi have set an array up called db. And you have set your variables in the array and done what I showed above. You need to call what you defined in the mysql_connect. So this piece of code is what you need:


<?PHP

//Database Information
$db['host'] = "fdb1.awardspace.com"; // try setting this to localhost
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<my password>";
$db['name'] = "lethalgaming_lg_users";

//Connect To The Database
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

?>

That should work aslong as you have the correct details set. Now go back and learn the basics, it will save you a lot of time later without having silly errors like these.

http://www.phpfreaks...orials/37/0.php

Matt

Edited by Mr. Matt, 17 December 2006 - 04:28 AM.


#15 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 12:06 PM

It still isnt working :), Here is the error that comes up again:

"Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/lethalgaming.awardspace.com/config.php on line 10
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

Here is my config.php code:

"<?PHP

//Database Information
$db['host'] = "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<My Password>";
$db['name'] = "lethalgaming_lg_users";

//Connect To The Database
mysql_connect($db['fdb1.awardspace.com'], $db['lethalgaming_lg'], $db['My Password']) or die(mysql_error());
mysql_select_db($db['lethalgaming_lg_users']);

?>"

Here is the beginning of register.php:

"<?PHP

session_start();
ob_start();

//Include the configurations
include('config.php');

//Define a few variables
$x = $_GET['x'];
$u = $_GET['u'];"

For the host ive tried "fdb1.awardspace.com" which is what the web host tells me to put, and ive tried "localhost" but i still get the same error.

Sorry for all of the help ive been needing.

Edited by pistonsfreak, 17 December 2006 - 12:07 PM.


#16 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 12:25 PM

Did you even read what I typed? The variables you are using in the mysql_connect() do not match the ones you have set above it.

Use this code and providing the details are correct, it will work!

<?PHP

//Database Information
$db['host'] = "localhost";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<my password>";
$db['name'] = "lethalgaming_lg_users";

//Connect To The Database
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

?>

Matt

#17 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 01:55 PM

oooo alright man i get it now i thought i was supposed to put the actual host and stuff in, in the connect part. sorry and thanks

Edited by pistonsfreak, 17 December 2006 - 02:01 PM.


#18 pistonsfreak

pistonsfreak

    Young Padawan

  • Members
  • Pip
  • 174 posts

Posted 17 December 2006 - 02:00 PM

When i put "fdb1.awardspace.com" as my host I get this message:

"Warning: mysql_connect(): Access denied for user 'lethalgaming_lg'@'64.69.36.238' (using password: YES) in /home/www/lethalgaming.awardspace.com/config.php on line 10
Access denied for user 'lethalgaming_lg'@'64.69.36.238' (using password: YES)"


And when I put "localhost" I get this:

"Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/lethalgaming.awardspace.com/config.php on line 10
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

Edited by pistonsfreak, 17 December 2006 - 02:01 PM.


#19 Hayden

Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 717 posts
  • Gender:Male
  • Location:Texas

Posted 17 December 2006 - 02:25 PM

so, then you know that the correct configuration should be:
//Database Information
$db['host'] = "fdb1.awardspace.com";
$db['user'] = "lethalgaming_lg";
$db['pass'] = "<my password>";
$db['name'] = "lethalgaming_lg_users";

//Connect To The Database
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']);

but for some reason, you're username and/or password is incorrect.

#20 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 17 December 2006 - 02:41 PM

Well make sure you change <my password> to what your password is (without the < >).

If that doesn't work, check with your host your db connect info.

Matt




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users