I have a PHP script which is supposed to send an email with a link which can be clicked to alter the last entry in the MySQL database. To do this I'm trying to include the primary key as a variable in the link but the variable is coming up blank or possibly just not sending correctly. I've never done this before so not sure what the problem is, probably something stupid but silly me has been stumped for a while.
The link in the email currently ends like this: feedback/approve/?id=
Here is the code, if you need more info let me know:
<?PHP
error_reporting(E_ALL);
require ('config.php');
require ('index.php');
/* Connection */
$table = "FeedbackWRW";
$conn = new mysqli (host, user, pass, db);
$sql = "INSERT INTO $table (answer1, answer2, answer3, answer4, name, detail1, detail3, title) VALUES ('$values')";
$primary = mysqli_fetch_row(mysqli_query($conn,"SELECT LAST(`primary`) FROM $table"));
$approvallink = "${clienturl}feedback/approve/?id=" . "$primary";
if(mysqli_query($conn, $sql)
&&
mail("$testemail",'Feedback Entry',
"
Satisfied customer: $answer1
Would recommend: $answer2
Testimonial: $answer3
Suggestion box: $answer4
Name: $name
Email: $detail1
Newsletter Opt-in: $detail3
To approve this entry, please click this link or paste it into your browser window:
$approvallink
","From: $clientemail
Reply-To: $detail2
Return-Path: $detail2
X-Mailer: PHP
CC:
BCC:
")
)
{header('Location: thankyou.php');
exit();
}
else { echo "Error: " . $sql . "<br>" . mysqli_error($conn);}
?>