Jump to content

Newbie Question


JREAM

Recommended Posts

I have a question!

 

If I have a link:

<a href='delete-user.php?id=$id'>Delete</a>

 

And instead I set it to

<a href='<?php echo $_SERVER['PHP_SELF']; ?>?id=$id'>Delete</a>

 

Ok so far!

 

Then I place the code that was in delete-user.php into the index.php.

 

I know how to check if a form was submitted, I just use the name of a form field..

 

So would I do something like this?

<a name="delete" href='<?php echo $_SERVER['PHP_SELF']; ?>?id=$id'>Delete</a>

 

Would that suffice for passing a delete variable through the page so I could do:

 

if (isset($_POST['delete'])) { // etc.. }

Link to comment
https://forums.phpfreaks.com/topic/145262-newbie-question/
Share on other sites

No, an anchor tag only "loads" the url into the browser. The URL, and only the URL, are passed. But, when passing parameters through a URL you can reference them using the $_GET global variable. Also, your code is wrong, the $id needs to be within PHP tags as well:

 

<a name="delete" href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $id; ?>">Delete</a>

 

if (isset($_GET['id'])) { // etc.. }

Link to comment
https://forums.phpfreaks.com/topic/145262-newbie-question/#findComment-762562
Share on other sites

you could just put another variable in the url

 

<a name="delete" href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $id; ?>&param=delete">Delete</a>

 

then in your page

<?php
if ($_GET['param'] == 'delete'){
//run delete code
}
?>

 

also use htmlentities($_SERVER['PHP_SELF']); in your urls... helps to prevent xss

Link to comment
https://forums.phpfreaks.com/topic/145262-newbie-question/#findComment-762606
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.