Hi everyone, am new with php and need some expert advice here. Am trying to save and display the textbox color upon selection of an option. The steps are as follows:
1. User select Selfrating option ie Good or Satisfactory
2. Upon option selection, textbox T11 will change color based on select option
3. After submit button click, textbox T11 suppose to save in mysql and display color in the same form
Currently the problem is with step 3 as the textbox doesn't save in mysql and doesn't display the color change. 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>