简体   繁体   中英

PHP/MySQL Error 1054 for form registration

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM