Reputation: 868
i am stuck,the select options value is sent but it sets the value to 0 all the time i execute the query. how can i get the value of the options to be grabbed ? i would be very grateful for the answer. thanks
here is the form for the select options
<select name="user_role" id="#user_role">
<option>
</option>
<option value="1">
Super Admin
</option>
<option value="2">
Team Manager
</option>
<option value="3">
Staff
</option>
</select>
the ajax function i set is
$(".save-update").click(function(e) {
e.preventDefault();
//alert("save button clicked");
var username = $("#username").val();
var email = $("#email").val();
var user_role = $("#user_role option:selected").val();
$.post("../lib/ajax/edit-user-save.php",{username:username,email:email,id:id,user_role:user_role},function(data){
//alert(data);
$(".save-update").parent().parent().addClass("table-list");
$(".save-update").parent().parent().replaceWith(data);
});
});
now, the edit-user-save.php where the query is done
if(isset($_POST['user_role'])){
$user_role = $_POST['user_role'];
//echo $id;
}
//$query = mysql_query();
$query = mysql_query("UPDATE users SET username='$username', email='$email',user_role='$user_role' WHERE id=$id");
if(!$query){
echo "could not update the table".mysql_error();
}
Upvotes: 1
Views: 9947
Reputation: 9034
Your ID is not correct in HTML, change this
id="#user_role"
to this
id="user_role"
Upvotes: 1
Reputation: 868
oh i got the answer, so stupid of me
id="#user_role"
i wrote # at the id .. haha ... !
Upvotes: 1