Petr Cihlar Petr Cihlar - 2 months ago 5
Javascript Question

form sends values that are not changing anything

I have a simple form:

<form id="change_id" action="change.php?change=profile"
method="POST" enctype="multipart/form-data">
<input id="change_username" required name="jmeno_new"
type="text" placeholder="New Username">

Also, I am sending data from my
element via AJAX request like so:

save_button.addEventListener('click', function ()
var fd = new FormData(change_id);
XXHR().request(change_id.getAttribute("action"), function(r){
var obj = JSON.parse(r);
if (obj.type == 'success')

else if (obj.type == 'success_un')
console.log("YEAH! THAT WORKS.");
}, function(){}, true, fd);
}, false);

And I get it with my PHP file like so:

$new_un = $_POST['jmeno_new'];
$sql_update = ("UPDATE myTable SET `name`='$new_un' WHERE `name`='$name'");
$out = array('type' => 'success_un');

So if the data is set, I can only see that AJAX request was successful, but it does not change anything in my database.

What it should do?

It should update
where it should replace the old name with the new one, got via

This does not work.. how? Why?


In case you use mysqli:

That's because you don't execute a query. Try to replace this line

$sql_update = ("UPDATE myTable SET `name`='$new_un' WHERE `name`='$name'");

with this one below:

$your_connection_variable->query("UPDATE myTable SET `name`='$new_un' WHERE `name`='$name'");

Hope that works! :)