0

I am trying to get my PHP to execute this script that inserts data from one table into another but with 2 WHERE conditions, "userID" AND "confirmation" but it is only working if I set only 1 WHERE condition i.e WHERE confirmation = :confirmation.

I need to have a AND so that the script only affects the individual session user (userID) rather than all users.

I tried using a comma instead of AND but still nothing.

I also tried typing them like userID = '$userID' AND confirmation = :confirmation but still nothing.

$charizard = $dbh->prepare("INSERT INTO orders (email, first_name, last_name, product, quantity, date, price)
(SELECT email, first_name, last_name, product, quantity, date, price FROM checkout WHERE userID = :userID AND confirmation = :confirmation)");
$charizard->bindParam(':userID', $userID);
$charizard->bindParam(':confirmation', $confirmation);

if ($charizard->execute())
{
  $delete_stmt = $dbh->prepare("DELETE FROM checkout WHERE userID = :userID AND confirmation = :confirmation");
  $delete_stmt->bindParam(':userID', $userID);
  $delete_stmt->bindParam(':confirmation', $confirmation);
  $delete_stmt->execute();
}
DaTZcodie
  • 11
  • 6
  • 1
    The field name could be incorrect, the PHP variable could be empty. If the SQL execcute is failing what is the SQL error / response? Did you turn on PHP errors to get the PHP errors? Did you echo the PHP values to make sure they made sense? – Dave S Feb 16 '23 at 01:00
  • @DaveS I know its working because when I only use one WHERE condition it works fine, its only when I add the `AND userID = :userID` then it doesnt work – DaTZcodie Feb 16 '23 at 01:06
  • That's the case that you need to be debugging: the PHP variables, PHP errors and warnings, SQL errors and warnings -- all when you have the AND. – Dave S Feb 16 '23 at 01:59
  • @DaveS is that like using `PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION` I've used this in my code many times before and it makes no difference to anything... – DaTZcodie Feb 16 '23 at 11:21

0 Answers0