0

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.

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Aser Gado
0

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.

0

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

Edited by Aser Gado: n/a

0
$sql = "INSERT INTO users (firstname, lastname, email, password)
    VALUES ('{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['email']}', '{$_POST['password']}')";
0

EDIT 2:

Everything works fine now, thanks.

Edited by Aser Gado: Problem Solved

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.