Originariamente inviata da tampertools Codice PHP: <?phpif (isset ($_POST['invia'])) { $camera= $_POST['camera']; if (isset($_POST['stato'])) { $stato= $_POST['stato']; } else { $stato=false; // Qui metti false } if (isset($_POST['manutenzione'])) { $manutenzione= $_POST['manutenzione']; // Checkbox is selected } else { $manutenzione='no M'; } $conn=mysql_connect("localhost", "root",""); $beta=mysql_select_db("sun2"); // E qui modifica così: $query = "UPDATE trestelle SET "; if ($stato !== false) { $query .= "stato= '$stato', " } $query .= "manutenzione='$manutenzione' WHERE camera='$camera'"; $gamma= mysql_query($query); $result=mysql_query("SELECT * FROM trestelle"); while($row= mysql_fetch_array($result)){ echo $row["camera"]." ".$row["stato"]." ".$row["manutenzione"]."<br />"; }}?> oppure risparmiando un if codice: if (isset($_POST['stato'])) { $stato= "stato='".$_POST['stato']."',"; } else { $stato=' '; } e la query "UPDATE trestelle SET $stato manutenzione='$manutenzione' WHERE camera='$camera' ")
<?phpif (isset ($_POST['invia'])) { $camera= $_POST['camera']; if (isset($_POST['stato'])) { $stato= $_POST['stato']; } else { $stato=false; // Qui metti false } if (isset($_POST['manutenzione'])) { $manutenzione= $_POST['manutenzione']; // Checkbox is selected } else { $manutenzione='no M'; } $conn=mysql_connect("localhost", "root",""); $beta=mysql_select_db("sun2"); // E qui modifica così: $query = "UPDATE trestelle SET "; if ($stato !== false) { $query .= "stato= '$stato', " } $query .= "manutenzione='$manutenzione' WHERE camera='$camera'"; $gamma= mysql_query($query); $result=mysql_query("SELECT * FROM trestelle"); while($row= mysql_fetch_array($result)){ echo $row["camera"]." ".$row["stato"]." ".$row["manutenzione"]."<br />"; }}?>
if (isset($_POST['stato'])) { $stato= "stato='".$_POST['stato']."',"; } else { $stato=' '; }
Ultima modifica di pippuccio76; 05-04-2014 a 21:46
Regole del Forum