Jump to content

SQL Insert Statement.


yerac8

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/272929-sql-insert-statement/
Share on other sites

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

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.