Good day to all of you. As the title says I need help about facebox when updating a data(s).
Here's the code for the button to show the facebox
echo '
td>
<a rel="facebox" href="../admin/c_status.php?id='.$row["userID"].'">Edit</a>
</td>
';
and here's the code inside facebox
<?php
include("../db/dbCon.php");
//$id = $_GET['id'];
//echo $id;
?>
Status
<form method="post">
<select name="selActive" id ="selActive">
<option value="ACTIVE">ACTIVE</option>
<option value="IN-ACTIVE">IN-ACTIVE</option>
<option value="GRADUATE">GRADUATE</option>
</select>
<br>
<br>
<button class="btn btn-success btn-block btn-large" name="saveChangeButton" id ="saveChangeButton">Save Changes</button>
</form>
<?php
if(isset($_POST['saveChangeButton'])){
$id = $_GET['id'];
$status = $_POST['selActive'];
$cStatus = $conn->prepare("UPDATE useraccount SET status = :status WHERE userID = :userID");
$cStatus->bindParam(':status', $status);
$cStatus->bindParam(':userID', $id);
$cStatus->execute();
}
?>
The problem I encounter is the data won't update via clicking the edit button BUT when I edit via address bar like "http://localhost/ict/admin/c_status.php". It will work.
You can make an input type hidden and just make its value equal to $_GET['id']
<form method="post">
<select name="selActive" id ="selActive">
<option value="ACTIVE">ACTIVE</option>
<option value="IN-ACTIVE">IN-ACTIVE</option>
<option value="GRADUATE">GRADUATE</option>
</select>
<input type="hidden" name="userid" value="<?php echo $_GET['id'];?>">
<br>
<br>
<button class="btn btn-success btn-block btn-large" name="saveChangeButton" id ="saveChangeButton">Save Changes</button>
</form>
then transfer you php code to update useraccount below or above your link.When you used facebox, the form you have opened as pop up became part of this file therefore it is logical to transfer your php code to update accounts here since you didn't specify the action attribute of the form above.
echo '<td>
<a rel="facebox" href="../admin/c_status.php?id='.$row["userID"].'">Edit</a>
</td>';
include("../db/dbCon.php");
if(isset($_POST['saveChangeButton'])){
$id = $_POST['userid'];
$status = $_POST['selActive'];
$cStatus = $conn->prepare("UPDATE useraccount SET status = :status WHERE userID = :userID");
$cStatus->bindParam(':status', $status);
$cStatus->bindParam(':userID', $id);
$cStatus->execute();
}
Hope that helps