0

I've been making steady progress up until the point I wanted the user to have a 'confirm' alert before deleting a row via PHP. Essentially, I need to pass the variable of the row's id number to the 'delete.php' page once the user has pressed 'ok'.

So the PHP prints out a button:

$clickid = $db_field['id'];
    print "<form><input type='button' onclick='confirmation()' value='Delete'></form>";

And my Javascript:

function confirmation() {
    var answer = confirm("You wish to delete this event?")
    if (answer){
        alert("Deleted")
        window.location = "http://www.xxxxxxx.co.uk/admin/delete.php<? "?id=$clickid "?>";
    }
    else{
        alert("Your Event is Not Deleted")
    }
}
</script>

It obviously runs through to the 'delete.php' page, but doesn't delete anything because $clickid seems to have no value passed to it. If anyone can spot where I am going wrong, or maybe something that would work, that would be great help.

4
  • remember semi-colons in javascript, the auto-insertion doesnt always work well Commented Feb 28, 2012 at 16:54
  • confusing that you tell the user the thing is deleted before you actually redirect. might want to write "Deleting" in that alert. Commented Feb 28, 2012 at 16:55
  • you need to post more code, there's no reason this shouldnt work. Commented Feb 28, 2012 at 16:57
  • remember that php and javascript have seperate interpreters and so on. i hope you assign the $clickid in your php code before you use it. might want to do set_error_reporting(E_ALL | E_STRICT) to check uninitialized var usage. Commented Feb 28, 2012 at 16:58

2 Answers 2

4
window.location = "http://www.xxxxxxx.co.uk/admin/delete.php?id=<?php echo $clickid; ?>";
Sign up to request clarification or add additional context in comments.

Comments

0
window.location = "http://www.xxxxxxx.co.uk/admin/delete.php<? "?id=$clickid "?>";

should this line not read more like this?

window.location = "http://www.xxxxxxx.co.uk/admin/delete.php?id="<?=$clickid ?>"";

Comments

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.