BAWANG GORENG
/
home
/
ecommerceavenue
/
ecommerceavenue.com
/
public_html
/
couronne205
/
tvchannels
/
manage
/
Nama File / Folder
Size
Action
_notes
--
NONE
_delete.php
2.572KB
Hapus
Edit
Rename
config.php
0.489KB
Hapus
Edit
Rename
delete.php
2.572KB
Hapus
Edit
Rename
index.php
4.596KB
Hapus
Edit
Rename
update.php
6.819KB
Hapus
Edit
Rename
<=Back
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $title = "Update DB"; // Include config file require_once "config.php"; // Define variables and initialize with empty values $channel_id = ""; $description = ""; $url = ""; $default_url = ""; $channel_id_err = ""; $description_err = ""; $url_err = ""; $default_url_err = ""; // Processing form data when form is submitted if(isset($_POST["id"]) && !empty($_POST["id"])){ // Get hidden input value $id = $_POST["id"]; echo $id . "<br />"; if ( empty($_POST["channel_id"]) ) { $input_channel_id = ""; } $input_channel_id = trim($_POST["channel_id"]); $channel_id = $input_channel_id; echo $channel_id . "<br />"; $input_description = trim($_POST["description"]); $description = $input_description; echo $description . "<br />"; $input_url = trim($_POST["url"]); $url = $input_url; echo $url . "<br />"; $input_default_url = trim($_POST["default_url"]); $default_url = $input_default_url; echo $default_url . "<br />"; // Prepare an update statement $sql = "UPDATE tv_channels SET channel_id=?, description=?, url=?, default_url=? WHERE id=?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "ssssi", $param_channel_id, $param_description, $param_url, $param_default_url, $param_id); // Set parameters $param_channel_id = $channel_id; $param_description = $description; $param_url = $url; $param_default_url = $default_url; $param_id = $id; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Records updated successfully. Redirect to landing page header("location: index.php"); exit(); } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } // Close connection mysqli_close($link); } else{ // Check existence of id parameter before processing further if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){ // Get URL parameter $id = trim($_GET["id"]); // Prepare a select statement $sql = "SELECT * FROM tv_channels WHERE id = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "i", $param_id); // Set parameters $param_id = $id; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ $result = mysqli_stmt_get_result($stmt); if(mysqli_num_rows($result) == 1){ /* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */ $row = mysqli_fetch_array($result, MYSQLI_ASSOC); // Retrieve individual field value $channel_id = $row["channel_id"]; $description = $row["description"]; $url = $row["url"]; $default_url = $row["default_url"]; } else{ // URL doesn't contain valid id. Redirect to error page header("location: error.php"); exit(); } } else{ echo "Oops! Something went wrong. Please try again later."; } } // Close statement mysqli_stmt_close($stmt); // Close connection mysqli_close($link); } else{ // URL doesn't contain id parameter. Redirect to error page header("location: error.php"); exit(); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title><?php echo $title; ?></title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> .wrapper{ width: 600px; margin: 0 auto; } </style> </head> <body> <div class="wrapper"> <div class="container-fluid"> <div class="row justify-content-md-center"> <h1><?php echo $title; ?></h1> <div class="col-md-12"> <hr /> <p>Please edit the input values and submit to update the records.</p> <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post"> <div class="form-group"> <label>id:</label> <div><?php echo $id; ?></div> </div> <div class="form-group"> <label>channel_id:</label> <input type="text" name="channel_id" class="form-control " value="<?php echo $channel_id; ?>"> <span class="invalid-feedback"><?php echo $channel_id_err;?></span> </div> <div class="form-group"> <label>description:</label> <input type="text" name="description" class="form-control " value="<?php echo $description; ?>"> <span class="invalid-feedback"><?php echo $description_err;?></span> </div> <div class="form-group"> <label>url:</label> <input type="text" name="url" class="form-control " value="<?php echo $url; ?>"> <span class="invalid-feedback"><?php echo $url_err;?></span> </div> <div class="form-group"> <label>default_url:</label> <input type="text" name="default_url" class="form-control " value="<?php echo $default_url; ?>"> <span class="invalid-feedback"><?php echo $default_url_err;?></span> </div> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <input type="submit" class="btn btn-primary" value="Submit"> <a href="index.php" class="btn btn-secondary ml-2">Cancel</a> </form> </div> </div> </div> </div> </body> </html>
Liking