0

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

}
6
  • have you checked with print_r($_GET); at the top to confirm that the data passes?? Commented Oct 15, 2014 at 7:07
  • 2
    Replace $temp = $_GET['$employeeid']; with $employeeid = $_GET['employeeid']; then do WHERE employeeid = ".$employeeid; Commented Oct 15, 2014 at 7:08
  • wowwwwwww this is why i hate coding late at night @_@ i spend all night thinking i dont understand the concepts and its dumbass syntax >.< Commented Oct 15, 2014 at 7:12
  • @JL Has my comment above fixed the problem? Commented Oct 15, 2014 at 7:12
  • well everyone sorta answered the problem at the same time lol. Commented Oct 15, 2014 at 7:13

6 Answers 6

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

awesome it really is too late for me to be doing all this coding >.< or maybe i just need more php practice
Everybody has gone to that 'scratch-your-head' stage when committing mistakes. Just continue practicing, as we all programmers do. :)
2

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>

1 Comment

thanks i hate it when I'm scratching my head forever over that kinda thing.
1

Make sure the Variable in GET Method that you are using $employeeid, May be it is employeeid

$temp = $_GET['employeeid'];

Comments

0

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

Comments

0

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>

Comments

0
$query = mysqli_query($link,"DELETE FROM employees WHERE employeeid ='$temp'");

1 Comment

Just a quick FYI: In mysqli_, the DB connection comes first, not last. See Johnroe's answer, that is the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.