-3

I'm not sure how to explain it properly or what to search for so sorry if this is a duplicate.

I have a page www.site.com/profile that will display the profile of different people. On that page is a form with a select and a submit button. The select has a dropdown list of people to choose from, and when the submit button is clicked, the page is reloaded with the chosen persons details. The information is sent via POST.

What I want to be able to do is go to www.site.com/profile/Barry%20Crouch, which will load the www.site.com/profile page with Barry Crouch as the POST data. So whatever name comes after the last slash is used as the selected players name.

I want this so I can link someone to the page and have the details of the person I am trying to show them displayed. Of course if the name is not in the list no details would be displayed, and I am using PDO prepared statements to prevent SQL injections.

darthspongebob
  • 119
  • 2
  • 7
  • what is the problem then? We do not write the code for you here. provide the code you've tried, and show the errors. And add more details to the question, what should happen if a user changes the /Barry%20Crouch to /Gareth%20Bale? Is it POSTed and processed? Then what s the point of using POST? use GET instead – Nodir Rashidov Feb 17 '17 at 01:10

1 Answers1

-1

When you write your select Make values to the options:

<form method="post" action="page you want to handle form data">
//action could also be action="<?php echo $_SERVER['PHP_SELF']; ?>" for same page
<select name='select'>
<option value="Berry Crouch">Berry Crouch</option>
//other options
</select>
<input type="submit" value="Submit">
</form>

now use php

<?PHP
if(isset($_POST['select']) && $_POST['select'] !== "")
{
    //your code to check database for the name
    //you can redirect to profile/$_POST['select'] or check database for name or w/e
}
else
{
    //nothing was selected or selection was blank
}
?>

Personally I would Never Do it this way. Any you should Use a file to parse your php EX:

profiles/profile.php?name= // Use the Name Here and You Can Then Change Database Based On $_GET['Name']; On your Database

http://php.net/manual/en/reserved.variables.get.php

POST VS GET

What is the difference between POST and GET?

Community
  • 1
  • 1