I can not update a specific column in DB

Ivan Golubar
Ivan Golubar used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Have you made any other changes to your code when posting this example? I just tried your code and it worked fine for me.

Author

Commented:
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?
Commented:
I don't think I understand what you're asking, but if you don't want to change the DB, comment out the code that changes it.

Author

Commented:
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?

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial