aQ Posted April 30, 2007 Share Posted April 30, 2007 Hello! I am a php-newbie, so don't please keep your replies easy to understand. I want to take data from the URL to do something. I'll try to explain. Let's say that I have this url: index.php?page=news&delete=4 4 is the "id"-field of a post in my mysql-database. I want to delete the post with the id 4 belongs to. I hope you understand. Thanks, aQ. Link to comment https://forums.phpfreaks.com/topic/49319-solved-get-data-from-url-newbie/ Share on other sites More sharing options...
map200uk Posted April 30, 2007 Share Posted April 30, 2007 I understand, data past in the url is a GET request and is stored in the GET array create a simple page, try and access it using page.php?bla=bla and on this page put print_r(_$GET); you will see the output of the get array with an element for bla mark Link to comment https://forums.phpfreaks.com/topic/49319-solved-get-data-from-url-newbie/#findComment-241668 Share on other sites More sharing options...
pedropedroc Posted April 30, 2007 Share Posted April 30, 2007 If deleting the post is a one-off requirement, and you have access to something like phpmyadmin, just delete the post through that. If you want to set up a more permanent solution, map200uk's will provide you with access to the data you need. Link to comment https://forums.phpfreaks.com/topic/49319-solved-get-data-from-url-newbie/#findComment-241675 Share on other sites More sharing options...
aQ Posted April 30, 2007 Author Share Posted April 30, 2007 Thank you map. I think you meant print_r($_GET)? Now I get this: Array ( => news [delete] => 6 ) What can I do with it to delete id 6 now? By the way: What is the difference between "print_r" and "print"? pedropedroc: I want to delete it using php since I don't want to go into phpmyadmin every time. Link to comment https://forums.phpfreaks.com/topic/49319-solved-get-data-from-url-newbie/#findComment-241677 Share on other sites More sharing options...
map200uk Posted April 30, 2007 Share Posted April 30, 2007 indeed i did mean $_GET , my mistake print_r recursively goes through arrays, as $_get is an array if we did print $_GET it will just say Array ( now to delete data with entry id6, okej $id=$_GET[delete]; we have create variable ID with the value of whatever delete was when the url was called we can now run a query and use the $id var (you could use $_GET[delete] without assigning to a var) i prefer to do it this way tho DELETE FROM bla WHERE id=$id Link to comment https://forums.phpfreaks.com/topic/49319-solved-get-data-from-url-newbie/#findComment-241685 Share on other sites More sharing options...
aQ Posted April 30, 2007 Author Share Posted April 30, 2007 Hey, that's great! Thank you a lot, it worked like a charm. Link to comment https://forums.phpfreaks.com/topic/49319-solved-get-data-from-url-newbie/#findComment-241691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.