0

I am building a travel website where people can build up their travel itineraries.

There are pre built itineraries with cities and the users can click a button "Add to Itinerary" and this adds to the databse - this work fine.

I also want the opportunity for the user to add their own cities. The way I want to do this is by them clicking a button similar to "Add to Itinerary" but then they enter the name of this city and add to the list that way.

This is the code I have for the "Add to Itinerary" which is working.

<?php
if ( $_SESSION['user'] != "" ) {
  if ( in_array("Bangkok", $aray) ) { ?>
    <button class="buttonAddedItinerary">Already Added </button>
  <?php
  } else {
    ?>
    <a href="process.php?action=addtoItinirary&UCty=Bangkok">
      <button class="buttonAddItinerary">Add to Itinerary</button>
    </a>
  <?php
  }
}
?>

So basically I want when I click the button:
<a href="process.php?action=addtoItinirary&UCty=USERINPUT"...

1
  • 1
    I will not answer with a workaround as every php beginners guide could help you ... One thing that I could suggest to you is: never trust what user input into your fields ;) Commented Mar 27, 2014 at 16:27

2 Answers 2

1

This is basic HTML form creation and processing. Any beginners PHP tutorial from the last 10+ years will show you how to do this. You will use method="GET" in your form tag.

Here's the tutorial from the PHP docs: https://www.php.net/manual/en/tutorial.forms.php

Sign up to request clarification or add additional context in comments.

2 Comments

I have had a go at a form and using get, but its not working. Is this completely wrong? <?php session_start(); if($_SESSION['user'] != ""){?> <form action="process.php" method="get"> Add Place: <input type="text" 'name="action=addtoItinirary&UCty="> ' <input type="submit"> ' </form>
make the name of the text input just "UCty" and create a separate hidden field named "action" with a value of "addtoItinirary". And check your spelling of "Itinirary" to make sure it's consistent.
0

You could use GET to pass user input and add it to the URL. So when when user input is present replace process.php?action=addtoItinirary&UCty=Bangkok with process.php?action=addtoItinirary&UCty=UserCity

Just sanitize the user input afterwards.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.