EDIT: This IS resolved. It was a simple case of querying the wrong schema name. The rest of the code works (even if it is not great coding practice).
This same question was asked here:
SQL statement not deleting in PHP
I don't see a solid resolution on that thread though. Basically my issue is that it says the delete was successful, but nothing was deleted. I'm pretty sure it has to do with the $1 in the delete statements, but I don't know what else to try. Could someone explain to me why this doesn't work? Here is my code:
$mySearch = $_POST['row'];
if($_POST['tbl'] == "country"){
$query = 'DELETE FROM lab2.country WHERE country.country_code = $1';
}
elseif($_POST['tbl'] == "city"){
$query = 'DELETE FROM lab2.city WHERE city.id = $1';
}
elseif($_POST['tbl'] == "language"){
$query = 'DELETE FROM lab2.country_language WHERE country_language.country_code = $1';
}
$stmt = pg_prepare($conn, $mySearch, $query); //prepare statement
$result = pg_execute($conn, $mySearch, array($mySearch)); //execute
if(!$result){ //error if no value in $result
die("Unable to execute: " . pg_last_error($conn));
} else{
//results are good so output them to HTML
echo "Delete was successful <br />";
echo "Return to <a href=\"" . $_SERVER['HTTP_REFERER'] . "\">search page</a>";
}
pg_free_result($result);
pg_close($conn);
return;