I want to change var code
value to "asd"
if data output is true but it is not working.
current result
jquery code :
$('.generate').click(function() {
var code = "vhe8t";
$.post('functions/functions.php', {
fun: "code_generate",
string: code
}, function(data) {
if (data == "true") {
code = "asd";
console.log("hello world");
}
})
console.log(code);
});
Function.php code
<?php
$connection = new mysqli("localhost", "root", "root", "shop_management");
$fun = "";
if (isset($_POST['fun'])) {
$fun = $_POST['fun'];
}
if ($fun == "code_generate") {
$code = $_POST['string'];
$query = "SELECT * FROM code WHERE code='$code'";
$run = mysqli_query($connection, $query);
$nums = mysqli_num_rows($run);
if ($nums > 0) {
echo 'true';
} else {
echo 'false';
}
}
?>