Registeration Error
Hello, how's everyone?
I have created a page with a form for registration and and another php to process the registration and create the rows in the database, but the processor comes with errors.
here is the PHP file:
<?php
include 'dbconnect.php';
mysql_query("INSERT INTO users (firstname, lastname, email, password)
VALUES ('$_POST[firstname]', '$_POST[lastname]', '$_POST[email]', '$_POST[password]')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "User created, you may now login.";
mysql_close($con);
?>
Here are the errors:
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /srv/disk4/566608/www/connectblog.eu.pn/register.php on line 6
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /srv/disk4/566608/www/connectblog.eu.pn/register.php on line 6
Warning: mysql_query(): 2 is not a valid MySQL-Link resource in /srv/disk4/566608/www/connectblog.eu.pn/register.php on line 8
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Thanks.
Aser Gado
Junior Poster in Training
52 posts since Feb 2011
Reputation Points: 10
Solved Threads: 1
Check your database credentials. The connect probably failed, thus triggering all these query errors.
Apart from that, line 5 runs a query for which you do not capture the result. Line 8 runs another, possible empty query.
pritaeas
Posting Expert
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
EDIT:
I edited it this is my new code now:
<?php
include 'dbconnect.php';
$sql = mysql_query("INSERT INTO users (firstname, lastname, email, password)
VALUES ('$_POST['firstname']', '$_POST['lastname']', '$_POST['email']', '$_POST['password']')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "User created, Thanks for Registrating";
mysql_close($con)
?>
and only one error occurred:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /srv/disk4/566608/www/connectblog.eu.pn/register.php on line 6
Aser Gado
Junior Poster in Training
52 posts since Feb 2011
Reputation Points: 10
Solved Threads: 1
$sql = "INSERT INTO users (firstname, lastname, email, password)
VALUES ('{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['email']}', '{$_POST['password']}')";
pritaeas
Posting Expert
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
EDIT 2:
Everything works fine now, thanks.
Aser Gado
Junior Poster in Training
52 posts since Feb 2011
Reputation Points: 10
Solved Threads: 1