Insert array (input data) to table in php? thanks!

columns in one table:

$name = "SELECT column_name
FROM information_schema.columns
WHERE table_name = a";

$data = $_POST['data'] (from input)

one column have one data except id column.
I want insert data into table,

foreach($data as $x) {
    $sql = "insert into a VALUES($x)";
	}

looks like the number is not match. please help me. thanks!

The data that your’re grabbing from the $_POST needs to be sanitized and then a prepared statement used for the insertion otherwise you leave yourself wide open to SQL Injection Attack

1 Like

What error do you get from MySQL?

Isn’t the “insert” query going to create a new row for each data item, rather than placing them in individual columns in the same row? I may be misunderstanding the question, though.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.