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.

Actually what suppose to happen is:
 
1.User select option Selfrating1
2.Once option has been selected, textbox T11 will change color based on select option
3.After submit button click, textbox T11 supposed to save color in mysql and display
Currently the problem is on No. 3 as the textbox T11 cannot be save in mysql and doesn't display the color change.
Please advise. Thanks.
 
 
 
 <?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); 
}
?> 
 

 

0   0
Aditya Singh
profile rosy 21st October 2023

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.

Write a comment ...
Post comment
Cancel
profile sophia 17th August 2015
Hi Lavi, thanks a lot for your reply. It works now. Thank you.
Write a comment ...
Post comment
Cancel
profile lavi 11th August 2015

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>

Write a comment ...
Post comment
Cancel

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