[solved] Script doesn't GET id variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

[solved] Script doesn't GET id variable

Post 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>
Last edited by Sindarin on Sat Aug 30, 2008 4:03 am, edited 1 time in total.
User avatar
lukewilkins
Forum Commoner
Posts: 55
Joined: Tue Aug 12, 2008 2:42 pm

Re: Script doesn't GET id variable

Post 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.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Script doesn't GET id variable

Post 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.
User avatar
lukewilkins
Forum Commoner
Posts: 55
Joined: Tue Aug 12, 2008 2:42 pm

Re: Script doesn't GET id variable

Post by lukewilkins »

Excellent, glad you got it working.

Luke
Post Reply