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"...
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: http://us1.php.net/manual/en/tutorial.forms.php
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.