0

I have a registration form on my website and I am getting Error 1054 when a person tries to register.

The PHP code is:

$con=mysql_connect("server","database","password");
// Check connection
if (!$con)
{
    echo "Failed to connect to MySQL" . mysql_errno();
}

$sql="INSERT INTO database.table (User_ID, Name, Email, Telephone, MyPassword)
VALUES
(NULL,'$_POST[name]','$_POST[email]','$_POST[telephone]','$_POST[mypassword]')";

if (!mysql_query($sql,$con))
{
    die('Error: you fail'.mysql_errno());
}
$User_Id= mysql_insert_id();

$sql="INSERT INTO database.table (Address1, Address2, Address3, Address4)
VALUES
('$_POST[address1]','$_POST[address2]','$_POST[address3]','$_POST[address4]')";
//Inserts address into Address table


if (!mysql_query($sql,$con))
{
    die('Error: you failed' . mysql_errno());
}
echo "Thank you for registering with Market Buddy";

mysql_close($con);

I put the code into an online compiler to get a more detailed error description and for this line:

('$_POST[address1]','$_POST[address2]','$_POST[address3]','$_POST[address4]')";

It gives me the following error:

Syntax error, unexpected t_encapsed and whitespace, expecting T_String or T_Variable or T_num_string.

jnthnjns
  • 8,962
  • 4
  • 42
  • 65
user2753810
  • 25
  • 2
  • 5
  • You need to escape your user input. See [here](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – juergen d Sep 10 '13 at 11:25

2 Answers2

0

Strictly First: Use mysqli_* instead of mysql_*, your query have sql injection threat possiblity, use prepared statement query...

Error 1054: this type of error mostly occur when the column name is not vaild, check your table as in my sense.

Dinesh
  • 447
  • 1
  • 6
  • 22
-1

You must use braces {}, when access to the array:

$sql="INSERT INTO database.table (Address1, Address2, Address3, Address4)
VALUES
('{$_POST["address1"]}','{$_POST["address2"]}','{$_POST["address3"]}','{$_POST["address4"]}')";

Edit: Error 1054 means bad column - are you sure, that mentioned columns exists in your table? http://dev.mysql.com/doc/refman/5.0/es/error-handling.html#error_er_bad_field_error

Honza
  • 974
  • 10
  • 18