JREAM Posted February 15, 2009 Share Posted February 15, 2009 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 More sharing options...
Psycho Posted February 15, 2009 Share Posted February 15, 2009 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 More sharing options...
JREAM Posted February 15, 2009 Author Share Posted February 15, 2009 Oh bummer. I will use a separate page so its not so cluttered i guess. Thank you for a fast reply Link to comment https://forums.phpfreaks.com/topic/145262-newbie-question/#findComment-762575 Share on other sites More sharing options...
Lodius2000 Posted February 15, 2009 Share Posted February 15, 2009 you could just put another variable in the url <a name="delete" href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $id; ?>¶m=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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.