PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm doing some basic php and MySQL and once more need a small hand. I've never tried list boxes with MySQL so this is something completely new to me.
Anyway, I have created a table with the following fields:
Service 1 Service 2 Service 3
Currently there is no value for any of the tables, as I want this to be controlled by a HTML list box. The options of the list box would be "Online" and "Offline". I have a PHP page created and linked up with the database, I just need help with the code so that once the list box is changed and the user clicks the "ok" button, the value for say Service 1 changes?
<?php
if (isset($_POST['service1'])) {
include('path/to/database.php'); // connect to the db
$service = $_POST['service1']; // get posted value
$insertSQL = mysql_query("INSERT INTO `table` (`column`) VALUES ('$service')", $conn) or die(mysql_error()); // insert into database
header("Location: path/to/success.php"); exit; // leave script
} else {
header("Location: path/to/naughty.php) exit; // just in case
}
?>
But if you want to change an existing value you should take a look at mysql's update. Also, you'd need a query before the form if you wanted to select either offline or online in the list dynamically. Sorry I can't be more specific!