Rating Issue
Hi everyone, am trying to save and display the textbox 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 textbox 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.
Ado Watermelon Game empowers the gaming community by providing a platform for self-expression, creativity, and shared experiences. Join a community of like-minded individuals who celebrate the joy of gaming and foster a supportive and inclusive environment for all.
For this you also need to add some java-script code .I have done this as below.
1. Created a 'db.php' file and written below code
<?php
$conn = mysql_connect('localhost','root','root');
mysql_select_db('test_php', $conn);
if($_POST) {
$query = "UPDATE colors SET color = '" .$_POST['color'] . "'";
$done = mysql_query($query);
if($done){
echo 'data inserted';
}
else {
echo 'something went wrong';
}
}
?>
2. Created a save_color.php and written below code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$('#choose').change(function(){
var color = $('#choose').val();
$('#area').css('background-color', color);
});
var colo = '';
function submit_color() {
var col = $('#area').css('background-color');
hexc(col);
$.ajax({
url: 'db.php',
type: 'post',
data: {"color" : colo},
success: function(res){
alert(res)
},
});
}
function hexc(colorval) {
var parts = colorval.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
delete(parts[0]);
for (var i = 1; i <= 3; ++i) {
parts[i] = parseInt(parts[i]).toString(16);
if (parts[i].length == 1) parts[i] = '0' + parts[i];
}
colo = '#' + parts.join('');
}
</script>
Please rotate your device
We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site