Search code examples
phpmysqlinsertmysql-error-1054

#1054 - Unknown column 'domain.com' in 'field list'


Ok, second question in two days... i am probably making a newb mistake here but i am stuck.

trying to insert a domain name into a table under the "name" column. all of my variables echo out so i know they are being passed and set.

the insert is as follows:

$newDomain = $_POST['newDomain']; //Get domain name
$newDomain_query =  mysql_query("INSERT INTO virtual_domains (name) VALUES ($newDomain)");
header("Location: domain_detail.php?domain=".$newDomain);

I have tried many ways of writing this script but everytime i get the same result when i include the:

or die(mysql_error)

in the script. the query does not run and when i take out the die part it just jumps to the header location.


Solution

  • You need to make sure that you enclose strings with quotes on your insert statement.

    Try this instead:

    $newDomain = $_POST['newDomain']; //Get domain name
    $newDomain_query =  mysql_query("INSERT INTO virtual_domains (name) VALUES ('$newDomain')");
    header("Location: domain_detail.php?domain=".$newDomain);