Hi everyone, am trying to save and display the text color after select change in php and html. After selecting Selfrating1 ie "Good", the textbox T11 suppose to change to "Green" color. After submit button the text color supposed to be save in mysql and display on the form. The Selfrating1 can be save and display but the textbox color goes back to black and it doesn't save in the mysql. Please advise. Thanks.
<div id="tabs-1"> <?php
session_start();
$con = mysql_connect("localhost","user","");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("p",$con);
$Picid = $_GET['Picid'];
$nwQty = "SELECT * FROM progress WHERE Picid = '$Picid'";
$solution = mysql_query($nwQty);
if(isset($_POST['submit'])){
if (mysql_num_rows($solution) == 0){
$sql = "INSERT INTO progress(T11,Selfrating1,Picid) VALUES ('" . $_POST["T11"] . "','" . $_POST["Selfrating1"] . "','" . $Picid . "')";
$result = mysql_query($sql);
}
else {
$sql =("UPDATE progress SET T11='" . $_POST["T11"] . "', Selfrating1='" . $_POST["Selfrating1"] . "'
WHERE Picid='" . $Picid . "'");
$result = mysql_query($sql);
echo('Record Updated');
}
$result = mysql_query("SELECT * FROM progress WHERE Picid='" . $Picid . "' ");
$row= mysql_fetch_array($result);
}
?> <script>
function ocalculateText(el) {
var form = el.form;
var idx = form.Selfrating1.selectedIndex;
if (idx <= 0) {
form.reset();
return;
}
if (form.Selfrating1.value == "Good") {
form.T11.value = "#008000";
} else if (form.Selfrating1.value == "Satisfactory") {
form.T11.value = "#9ACD32";
}
}
</script>
<p>a.i.Self Rating(1st Rating): <select name="Selfrating1" id="Selfrating1" onchange="ocalculateText(this)" value="<?php echo $row['Selfrating1']; ?>" >
<option selected>Please select an option</option> <option value=Good <?php if($row['Selfrating1']=='Good') { echo "selected"; }?>>Good</option>
<option value=Satisfactory <?php if($row['Selfrating1']=='Satisfactory') { echo "selected"; }?>>Satisfactory</option>
</select>
<input type="color" name="T11" id="T11" onchange="ocalculateText(this)" value="<?php echo $row['T11'];?>"></p> <input type="hidden" name="Picid" id="Picid" value="<?php echo $row['Picid']; ?>" >
<td colspan="2"><input type="submit" name="submit" value="Save" class="btnSubmit"></td> </div>