Hello! I am trying to use post data to make decisions about what data to insert into my sql database and what products to reject, and inform the user. I do not get any syntax errors, or a 500 error. All i get is a blank html page and no change in the database. I am not sure how to troubleshoot this, but I am pretty sure I am doing something fundamentally wrong.
Please let me know if you need more info.
Thanks.
<?php
$db_host = "host";
$db_username = "username";
$db_pass = "pass";
$db_name = "name";
$pdo = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$sql = "INSERT INTO product
SELECT new_prod_id, name, company, image FROM add_new_product WHERE new_prod_ID = '".$key."'
DELETE FROM add_new_product WHERE id = '".$key."';";
$stmt = $pdo->prepare($sql);
print_r($_POST);
foreach($_POST as $data)
$key = key($data);
echo $key;
$user_ID = "select user_ID from add_new_product where new_prod_ID ='".$key."' ";
echo $user_ID;
$username = "select username from users where usersID ='".$user_ID."' ";
echo $username;
$user_email = "select email from users where usersID = '".$user_ID."' ";
echo $user_email;
if ($data == "1"){
$stmt->execute();
echo "Data was 1";
}
else{
$msg = "Hello '".$username."', you recently submitted a product to 4UM. We regret to inform you that your product was not approved, likely because of insufficent proof uploaded \nIf this was not accurate,
please resubmit your product with improved proof so we may approve it. \nThank you for using 4UM!";
$msg = wordwrap($msg,70);
mail($user_email, "4UM New Product Rejection",$msg);
}
?>