Hello everyone, new to site hoping to find help with a MySQL Query problem. Been banging my head on the wall for weeks and can not figure out what the issue is.
Quick BreakDown
user selects option from form (single value)
on submit processes in same page.
Script gets to
$sql = "UPDATE `status` SET `system_status`= '<label class='text-danger'> Maint Mode </label>' WHERE `id`= '$maint_mode'";
And fails to Execute unsure as to why as I have ran:
UPDATE `status` SET `system_status`= '<label class='text-danger'> Maint Mode </label>' WHERE `id`= '1'
with phpmyadmin simulate query and have no issues. Record is updated no errors
Page out:
Form Data Received.
Data = 1
ERROR:Could Not Execute
UPDATE status
SET system_status
= ’ Maint Mode ’ WHERE id
= ‘1’
I have PHP error reporting E_ALL turned on
in php.ini
have these turned on
php_flag display_startup_errors on
php_flag display_errors on
error log shows no errors
-----------Form------------
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="POST">
<div class="row g-3">
<div class="col">
<h5 class="modal-title">Maintenance Mode</h5>
<p>Select system below to PLACE in Maintenance Mode.</p>
<div class="input-group mb-3">
<div class="input-group">
<select class="form-select" id="maint_mode_on" name="maint_mode_on">
<option value=""></option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
<option value="6"> 6 </option>
<option value="7"> 7 </option>
<option value="8"> 8 </option>
<option value="9"> 9 </option>
<option value="10"> 10 </option>
<option value="11"> 11 </option>
<option value="12"> 12 </option>
</select>
</div>
<input name="maint_mode_active" type="submit" id="maint_mode_active" value=" Maint Mode " class="btn btn-outline-warning">
</div>
</div>
</div>
</form>
----Processing Section -----
<?php
// Check Form Was Submitted
if (isset($_POST['maint_mode_active'])) {
$maint_mode = $_POST['maint_mode_on'];
echo "Form Data Received.<br /> Form Data = $maint_mode ";
// Connection
$mysqli = new mysqli("localhost", "username", "password", "database");
if($mysqli === false){
die("ERROR: Could Not Connect To Database. <br /> "
. $mysqli->connect_error);
} else{
echo 'Connected To Database. ';
}
$sql = "UPDATE `status` SET `system_status`= '<label class='text-danger'> Maint Mode </label>' WHERE `id`= '$maint_mode'";
if($mysqli->query($sql) === true){
echo " <br />$maint_mode_on System is in Maint Mode!";
} else{
echo "<br />ERROR:Could Not Execute <br /> $sql "
. $mysqli->error;
}
$mysqli->close();
}
?>
----- FULL SCRIPT —
<?php
ini_set('error_reporting', E_ALL);
?>
<html>
<head>
<title>Updating MySQL Update Record Test 2.0</title>
</head>
<body>
<?php
if (isset($_POST['maint_mode_active'])) {
$maint_mode = $_POST['maint_mode_on'];
echo "Form Data Received.<br /> Data = $maint_mode ";
$mysqli = new mysqli("localhost", "username", "password", "database");
if($mysqli === false){
die("ERROR: Could Not Connect To Database. <br /> "
. $mysqli->connect_error);
}
else{
echo 'Connected To Database. ';
}
$sql = "UPDATE `status` SET `system_status`= '<label class='text-danger'> Maint Mode </label>' WHERE `id`= '$maint_mode'";
if($mysqli->query($sql) === true){
echo " <br />$maint_mode_on System is in Maint Mode!";
} else{
echo "<br />ERROR:Could Not Execute <br /> $sql "
. $mysqli->error;
}
$mysqli->close();
}
?>
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="POST">
<div class="row g-3">
<div class="col">
<h5 class="modal-title">Maintenance Mode</h5>
<p>Select system below to PLACE in Maintenance Mode.</p>
<div class="input-group mb-3">
<div class="input-group">
<select class="form-select" id="maint_mode_on" name="maint_mode_on">
<option value=""></option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
<option value="6"> 6 </option>
<option value="7"> 7 </option>
<option value="8"> 8 </option>
<option value="9"> 9 </option>
<option value="10"> 10 </option>
<option value="11"> 11 </option>
<option value="12"> 12 </option>
</select>
</div>
<input name="maint_mode_active" type="submit" id="maint_mode_active" value=" Maint Mode " class="btn btn-outline-warning">
</div>
</div>
</div>
</form>
</body>
</html>