I've got a table in the database mshop2, named userdb. It has columns:
- ID
- name
- username
- password
My js file with all the functions stored in them is named mshop2.script, where me deleteUser function is also stored, which will jump to a file named deleteUser.php
The php file where I want the code to run on is admin.php and It's got these written in it:
<font color="white">Deletion - ID</font>
<input class="test1" type="text" id="txUserid" value="">
<input class="test2" name="Submit" type="submit" value="" id="submit"
onClick='deleteUser();txUserid.value="";'/>
the 'input class' words are just going to match an image folder according to my css file to show an image that I want the code to run on when I click it so don't mind it. I have included these lines in the head of my .php file:
<script src='jquery.js'></script>
<script src='mshop2.script.js'></script>
I've written this on my mshop2.script.js file:
function deleteUser(){
var userid = $('#txUserid').val();
var finalData = {
uid: userid
};
$.post('deleteUser.php', finalData, function(resp){
if(resp == 'success'){
alert('User successfully deleted.');
getUserList();
}
});
}
This is the contents of my deleteUser.php file:
<?php
include 'config.php';
$id = mysql_real_escape_string($_POST["userid"]);
$q = "DELETE FROM userdb WHERE ID = '$uid'";
if(!mysql_query($q, $con)){
die('Error: ' . mysql_error());
echo mysql_error();
}else{
echo 'success';
}
mysql_close($con);
?>
Nothing is happening and if I enter '1' into the text box or any number from 1 to 5 the matching line in my table in database with the same ID that I entered won't get deleted.
What is wrong with my code?