Jump to content

[SOLVED] Get data from URL (newbie)


aQ

Recommended Posts

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
Share on other sites

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
Share on other sites


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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.