I have a lot of variables that I'm adding into a database from all the product pages on my website. Here is my PHP code:
$args = (array(
"post_type" => "page",
"meta_key" => "_wp_page_template",
"meta_value" => "products.php",
"posts_per_page" => 50
));
$queryPages = get_posts($args);
$con= mysqli_connect("localhost","pmdot","password","pmd_ot");
foreach($queryPages as $qp) {
$qpID = $qp->ID;
$name = get_post_meta($qpID, "pmd_name", true);
$code = get_post_meta($qpID, "pmd_sku", true);
$installation = get_post_meta($qpID, "pmd_installation", true);
$age = get_post_meta($qpID, "pmd_agefrom", true);
$length = get_post_meta($qpID, "pmd_length", true);
$width = get_post_meta($qpID, "pmd_width", true);
$height = get_post_meta($qpID, "pmd_height", true);
$areal = get_post_meta($qpID, "pmd_areal", true);
$areaw = get_post_meta($qpID, "pmd_areaw", true);
$cfh = get_post_meta($qpID, "pmd_cfh", true);
$weight = get_post_meta($qpID, "pmd_weight", true);
$type[] = get_post_meta($qpID, "pmd_playtype", true);
$accred[] = get_post_meta($qpID, "pmd_accreditation", true);
$descr = get_post_meta($qpID, "pmd_shortdesc", true);
$price = get_post_meta($qpID, "pmd_price", true);
mysqli_query($con, 'INSERT INTO pmd_productdata (Product_ID, Product_Name, Product_Code, Product_Installation, Age_Range, Product_Length, Product_Width, Product_Height, Minimum_Area_L, Minimum_Area_W, C_F_H, Product_Weight, Play_Type, Accreditations, Product_Desc, Product_Price)
VALUES ($qpID, $name, $code, $installation, $age, $length, $width, $height, $areal, $areaw, $cfh, $weight, "placeholder", "placeholder", $descr, $price') or die ('Error:' .mysqli_error($con));
}
What this is doing is getting all the posts with the template products.php and then using all the custom fields to populate an SQL table with a query.
NOTE: The arrays that you can see are not currently being used in the query as I thought that was the issue. Bonus points if someone can help me get all the values in that array to display in the respective field.
All of the columns in my table have varchar(255) as their char base, just in case some are not INTs when they should be.
For some reason, I'm getting this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Now, as you can see the error is rather unclear, if anyone can shine some light on the situation I'd be very grateful.
My question is: Why am I getting that error, and what does it mean?
EDIT [Resolved]
Now I'm getting a new error that I've fixed the VALUES () issue:
Unknown column '$qpID' in 'field list'
Is this because I need to separate the variables from the query: e.g.:
'VALUES (' . $qpID . ', ' . $name . ')' etc.;
EDIT 2
The errors have now been fixed and the data is in the SQL Database, all I need now is to figure out how to get the 2 arrays to print all their values into the respective column.