So I have already converted most of my queries into prepared statements but I'm stumped on this one. All the examples I have found are for simple one-line queries but I have one that is a little complex and bases itself off other results.
To clarify, I don't know how to make this a prepared statement so I'm asking how you would do that. I might be overthinking it but it didn't work when I tried. Deleted my source code I attempted it at last night.
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
$ten_id = $_GET['parent'];
$end_d = $_POST["end_d"];
$results = $mysqli->query("SELECT property_id FROM tenancy WHERE tent_id = '$ten_id' AND current = 1");
while($row = $results->fetch_array()) {
$property = $row["property_id"];
}
$mysqli->query("
UPDATE tenant SET current='0' WHERE id=' $ten_id';
");
$mysqli->query("
UPDATE property SET occupied='0' WHERE id=' $property';
");
$mysqli->query("
UPDATE tenancy SET current='0', end_date='$end_d' WHERE tent_id='$ten_id' AND current = 1;
");
?>
I'm not asking you to just convert this to prepared statements. If you do great but please explain how you got there. I don't understand how to write the first row then fetch it to get the id and then update the other 2 rows in other tables