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.

Recommended Answers

All 4 Replies

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.

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
$sql = "INSERT INTO users (firstname, lastname, email, password)
    VALUES ('{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['email']}', '{$_POST['password']}')";

EDIT 2:

Everything works fine now, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.