I am very very new to MySQL, I have two arrays, whose output looks like this:
Array
(
[0] => Product/service
[1] => Product/service
[2] => Non-profit organization
[3] => Community
[4] => Company
[5] => Non-profit organization
[6] => Website
[7] => Book
[8] => Arts/humanities website
[9] => Public figure
)
I have a table (with a variable name) and two column names, the above array is called "category" and I would like to have a table where there would be a column named "category" which would just list these elements. I have tried the code below but it does nothing:
mysql_connect('127.0.0.1','root','') or die(mysql_error());;
mysql_select_db("DBName") or die(mysql_error());;
mysql_query("CREATE TABLE `".$tablename."` ( category VARCHAR(30), name VARCHAR(30))");
foreach($category as $k=>$v)
{
mysql_query("INSERT INTO".$tablename. "(category) VALUES".$v);
}
$tablenameis being setmysql_*functions. As ofPHP 5.5.0they are deprecated. Use something like PDO or MySQLiINSERTsyntax.INSERT INTO (category) VALUES ('value')You're missing().if (!mysql_query(...)) echo mysql_error()and you'll see it's complaining about syntax errors in the query.