Reputation: 367
I tried everything I could find online to get it to work, I tried casting $employeeid to int after retrieving it from the link (even though they say mysql does it for you), i tried using nested single quotes, escape quotes... the print line happens to work, and employeeid shows up as a number in the hyperlink when delete is clicked, but it never deletes. what could I be doing wrong?
also, I could've sworn the onclick="return confirm("")" in the hyperlink was supposed to cause a pop up to appear, but it didnt, am I forgetting something here as well or is it a syntax issue?
this is my php link that calls it:
<td><a href='employ.php?delete=yes&employeeid=$employeeid onclick=\"return confirm(\"Are you sure\")\"'>Delete</a></td>
and this is the code section that is supposed to handle it:
if(isset($_GET['delete']))
{
$temp = $_GET['$employeeid'];
print "teseting delete<br><br>";
$query = "DELETE FROM employees WHERE employeeid = ".$temp;
mysqli_query($link, $query); //link query to database
print "Employee Updated"; // print confirmation
}
Upvotes: 0
Views: 148
Reputation: 722
$query = mysqli_query($link,"DELETE FROM employees WHERE employeeid ='$temp'");
Upvotes: 0
Reputation: 1064
Try this I hope this may helpful
if(isset($_GET['delete']))
{
$temp = $_GET['employeeid'];
print "teseting delete<br><br>";
$query = "DELETE FROM employees WHERE employeeid = ".$temp;
mysqli_query($link, $query); //link query to database
print "Employee Updated"; // print confirmation
}
<td><a href="test.php?delete=yes&employeeid=<?=$employeeid;?>" onclick= 'return confirm("Are you sure")'>Delete</a></td>
Upvotes: 0
Reputation: 56
check your table name , field name ,user permission in mysql and relation with other table . if u use foreign key of employeeId in another table then also you not able to delete
Upvotes: 0
Reputation: 1069
Try this:
PHP
if(isset($_GET['delete']))
{
$temp = $_GET['employeeid']; <<=== remove the $ sign
print "teseting delete<br><br>";
$query = "DELETE FROM employees WHERE employeeid = ".$temp;
mysqli_query($link, $query); //link query to database
print "Employee Updated"; // print confirmation
}
And on your link:
<td>
<a href="employ.php?delete=yes&employeeid=$employeeid" onclick= 'return confirm("Are you sure")'>Delete</a>
</td>
Take note on the href
attribute, it is enclosed in double quotes since you are putting PHP variables in your link
Upvotes: 2
Reputation: 9782
Make sure the Variable in GET Method that you are using $employeeid
, May be it is employeeid
$temp = $_GET['employeeid'];
Upvotes: 1
Reputation: 782653
href
andonclick
are separate attributes, you have them combined into one.
<td><a href='employ.php?delete=yes&employeeid=$employeeid' onclick='return confirm(\"Are you sure\")'>Delete</a></td>
Upvotes: 2