Link to home
Start Free TrialLog in
Avatar of Ivan Golubar
Ivan Golubar

asked on

I can not update a specific column in DB

I am using input type color as i want to save selected color to DB.
I can see color which I did choose in console (check js), but something  gets wrong with ajax as I can not get echo "nnnnnnnn", but just "mmmmmmmmmmm" (check php).
So I might not debug forward in case of other errors.


php
<?php
echo "mmmmmmmmm"; 
if(isset($_POST["uColorIsSet"])){
 echo "nnnnnnnnnnnn";    
include_once("/wp-content/themes/n4/php_includes/db_conx.php");
$uColor2 = mysqli_real_escape_string($db_conx,$_POST['uColor2']);
$sql = "UPDATE users SET yourColor='$uColor2' WHERE username='$u'";
$query = mysqli_query($db_conx, $sql);
}
?>

Open in new window

and js
function updateAll2(event) {
var uColorIsSet=0;
 var uColor2 = event.target.value;
 console.log("selected color"+uColor2);
$.ajax({
  method:"POST",
  url: '/wp-content/themes/n4/nF4/user.php',
  data:  {
    "uColorIsSet":1,
    "uColor2":uColor2
    },
    datatype: "text",
    success: function(strdate){
   
      console.log("aaaaaaaaaaaaaa");
     
     },
     error: function(error, txtStatus) {
      console.log(txtStatus+" error on load of canvas on user page");
      console.log('error');
    }
 });
}

Open in new window


Can you see from data that I  provided what is the problem?


Just for  Info: I am doing the initial setting of color as next.
      
$sql = "INSERT INTO users (yourColor)    VALUES ('$c')";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ivan Golubar
Ivan Golubar

ASKER

I have other code also but ,

 success: function(strdate){
   
      console.log("aaaaaaaaaaaaaa");
     
     }

Open in new window

   
How is possible to get answer in console and no changes in DB?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for bad question. I will ask differently.

How is it possible that I am  getting  answer in console to confirm me that ajax was executed successfully, but then   there were no changes in DB?
I am using now :
$db_conx=mysqli_connect("localhost","xxxxxxxx","yyyyyyyy","zzzzzzzz")or die ("no connection"); 

Open in new window


instead of
include_once("/wp-content/themes/n4/php_includes/db_conx.php");

Open in new window


and is working.