frobak Posted February 6, 2009 Share Posted February 6, 2009 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 More sharing options...
omfgthezerg Posted February 6, 2009 Share Posted February 6, 2009 Can you post your table structure of the customers table? Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756081 Share on other sites More sharing options...
frobak Posted February 6, 2009 Author Share Posted February 6, 2009 CREATE TABLE customers( customer_id INT(15), company_name VARCHAR(20), address_line1 VARCHAR(20), address_line2 VARCHAR(20), City VARCHAR(20), postcode VARCHAR(, 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 More sharing options...
flyhoney Posted February 6, 2009 Share Posted February 6, 2009 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 More sharing options...
frobak Posted February 6, 2009 Author Share Posted February 6, 2009 thank but this still doesnt work, i am still getting the same error Unknown column 'company_name' in 'field list' surely this is something really simple? Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756121 Share on other sites More sharing options...
flyhoney Posted February 6, 2009 Share Posted February 6, 2009 Apparently the table you are inserting into does not have a company_name column. Check your database. Maybe the table wasnt created the way you think it was. Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756123 Share on other sites More sharing options...
frobak Posted February 6, 2009 Author Share Posted February 6, 2009 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( 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 More sharing options...
flyhoney Posted February 6, 2009 Share Posted February 6, 2009 Have you actually logged into mysql and done a "SHOW TABLES" query or and "EXPLAIN TABLE customers" ? Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756128 Share on other sites More sharing options...
frobak Posted February 6, 2009 Author Share Posted February 6, 2009 yes ive just copied the above table structure direct from phpmyadmin? Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756131 Share on other sites More sharing options...
frobak Posted February 6, 2009 Author Share Posted February 6, 2009 can you mark this as solved, im stupid! Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756134 Share on other sites More sharing options...
dennismonsewicz Posted February 6, 2009 Share Posted February 6, 2009 did you figure out the problem? or are you just calling yourself stupid? The stupid thing to do would be to walk away from this not learning anything Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756136 Share on other sites More sharing options...
frobak Posted February 6, 2009 Author Share Posted February 6, 2009 yeah sorry i solved it, my db include file was wrong, so it was looking at my old server and database! Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756145 Share on other sites More sharing options...
dennismonsewicz Posted February 6, 2009 Share Posted February 6, 2009 ah gotcha... well i am glad you figured out the problem though bro Link to comment https://forums.phpfreaks.com/topic/144097-simple-php-insert/#findComment-756189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.