yerac8 Posted January 10, 2013 Share Posted January 10, 2013 Good Day all.. I am querying entrants from on table and placing them in another table. When I query the entrants, store them in an array and echo them, I can see that the tables are being accessed and the values are being read. However when i query to put the values into the other, if I put in the entrants with numbers only ( float type or integer type), the following statement works but it doesnt work for the entrants that are of type VARCHAR Here is the statement I use. it works for this $query = mysql_query("INSERT INTO store_data (network_ID, store_num) VALUES ($network_ID, $store_num)"); Doesnt work for this $query = mysql_query("INSERT INTO store_data (network_ID, store_name, store_num, store_type) VALUES ($network_ID, $store_name, $store_num, $store_type)"); $network_ID is an 'int' $store_name is a 'VARCHAR(255) $store_num is an 'int' $store_type is a 'VARCHAR(255) can anybody tell me what wrong? Quote Link to comment Share on other sites More sharing options...
Dharmender Posted January 10, 2013 Share Posted January 10, 2013 Try This $query = mysql_query("INSERT INTO store_data (network_ID, store_name, store_num, store_type) VALUES ($network_ID, '$store_name', $store_num, '$store_type')"); The column values with varchar types should be in single quotes Quote Link to comment Share on other sites More sharing options...
requinix Posted January 10, 2013 Share Posted January 10, 2013 You should also be escaping the strings. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 10, 2013 Share Posted January 10, 2013 I also recommend reading this post. It'll teach you how to properly debug your SQL problems, by adding error checking (and logging) to them. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 10, 2013 Share Posted January 10, 2013 There is no need to SELECT data Store in an array foreach array item INSERT into a table from array. You can do it with a single query instead of multiple queries in a loop (which is bad practice). INSERT INTO table2 SELECT whatever FROM table1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.