Jump to content

simple php insert?


frobak

Recommended Posts

Hi i have this simple php insert statement, but whatever i try it says:

 

Unknown column 'company_name' in 'field list'

 

all the column names are the same in my html documnt, this statement here and in my database table. Thsi is really simple and driving me mad

 

<?

if($_POST['add']) {

 

include("includes/db_connect.inc.php");

$sql = ("INSERT INTO customers

(company_name, address_line1, address_line2, city, postcode, contact_name, emailaddress, webaddress, phone, fax, mobile) VALUES

('$_POST[company_name]', '$_POST[address_line1]', '$_POST[address_line2]', '$_POST[city]', '$_POST[postcode]', '$_POST[contact_name]',

'$_POST[emailaddress]', '$_POST[webaddress]', '$_POST[phone]', '$_POST[fax]', '$_POST[mobile]')");

 

$result = @mysql_query($sql,$connection) or die(mysql_error());

}

 

?>

 

any help much appreciated.

 

cheers

Link to comment
https://forums.phpfreaks.com/topic/144097-simple-php-insert/
Share on other sites

CREATE TABLE customers(

customer_id INT(15),

company_name VARCHAR(20),

address_line1 VARCHAR(20),

address_line2 VARCHAR(20),

City VARCHAR(20),

postcode VARCHAR(8),

contact_name VARCHAR(25),

emailaddress VARCHAR(25),

webaddress VARCHAR(25),

phone VARCHAR(20),

fax VARCHAR(20),

mobile VARCHAR(20));

Link to comment
https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756085
Share on other sites

This syntax is a million times easier:

 

$query = "
INSERT INTO 
customers
SET
company_name  = '$_POST[company_name]', 
address_line1 = '$_POST[address_line1]', 
address_line2 = '$_POST[address_line2]', 
city          = '$_POST[city]', 
postcode      = '$_POST[postcode]', 
contact_name  = '$_POST[contact_name]', 
emailaddress  = '$_POST[emailaddress]', 
webaddress    = '$_POST[webaddress]', 
phone         = '$_POST[phone]', 
fax           = '$_POST[fax]', 
mobile        = '$_POST[mobile]'
";

Link to comment
https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756115
Share on other sites

but heres the table, copied directly from mysql?  the columns there?

 

customer_id  int(15)  No     

company_name varchar(20) Yes  NULL 

address_line1 varchar(20) Yes  NULL 

address_line2 varchar(20) Yes  NULL 

City varchar(20) Yes  NULL 

postcode varchar(8) Yes  NULL 

contact_name varchar(25) Yes  NULL 

emailaddress varchar(25) Yes  NULL 

webaddress varchar(25) Yes  NULL 

phone varchar(20) Yes  NULL 

fax varchar(20) Yes  NULL 

mobile varchar(20) Yes  NULL

Link to comment
https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756126
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.