Page 1 of 1

[solved] Script doesn't GET id variable

Posted: Fri Aug 22, 2008 12:14 pm
by Sindarin
I use the $newsid variable to get the ID of a news article from the database. It worked, I could delete an article by clicking a link, but I decided to add a confirm box to confirm that the user really wanted to delete it. Problem is that when I click OK on the confirm box the following location is parsed "http://localhost/testing/show.php?action=delete&id=", which as you see the id variable appears to be blank now. Is something wrong the way I do this? Something with the script?

Code: Select all

<script language=\"javascript\">
function confirm_delete()
{
var deleteok = confirm(\"Do you really want to delete this article?\")
if (deleteok)
{
//delete entry
window.location = \"show.php?action=delete&id=$newsid\";
}
else
{
alert(\"Cancelled!\");
}
}
</script>

Re: Script doesn't GET id variable

Posted: Fri Aug 22, 2008 1:51 pm
by lukewilkins
Sindarin,

First of all, you are now in JavaScript and not PHP so you should have something like:

Code: Select all

window.location = "show.php?action=delete&id=<?php echo $newsid; ?>";
and you need to make sure you are still pulling that variable from the database at this point on your page.

I notice the escaped quotes in your script. Are you echoing this from PHP? If you still can't figure it out, post your full script and I'll take a look. I'm pretty sure it is just a simple fix.

Re: Script doesn't GET id variable

Posted: Fri Aug 22, 2008 6:18 pm
by Sindarin
Yes, it worked for me. However I found a better way to do this with no js prompts. Used a switch and a confirmation message pops at the top. Easy and nice looking. :D Thanks.

Re: Script doesn't GET id variable

Posted: Sat Aug 23, 2008 12:26 am
by lukewilkins
Excellent, glad you got it working.

Luke