I have the following code to pass a variable id (primary key in meeting table) from viewMeeting.php to modifyMeeting.php
Under viewMeeting.php:
<a href="modifyfinalmeeting.php?id=<?php echo $id ?>"><?php echo $nameMeeting; ?></a>
Eg of URL: http://localhost/MyProject/modifyMeeting.php?id=1
Under modifyMeeting.php:
//get ID from URL
if (isset($_GET['id'])) {
$id =$_GET['id'];
}
if (isset($_POST['updatebtn'])) {
$sql = 'UPDATE meeting SET nameMeeting = ?, venue = ? WHERE id = ?';
if ($stmt = mysqli_prepare($link, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, 'sss', $nameMeeting, $venue, $id);
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
//Alert to redirect
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Succesfully Updated')
window.location.href='viewfinalmeeting.php';
</SCRIPT>");
} else {
echo "Something went wrong. Please try again later.";
}
}
}
<button type="submit" name="updatebtn" class="btn btn-primary">Update</button>
If i hardcode the variable for $id (eg: $id = 2), it will update the database.
However, currently it will show "Successful Updated" but not update the database to the corresponding $id from the GET variable.
I also tried the following method but it does not work as it shows undefined function:
$id = mysql_real_escape_string($_GET['id'])
Please, any help as to how to update the database will be greatly appreciated!