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