I'm doing a flight booking site with PHP for my assignment. The search page returns a table of related flight details from the key word that was entered. Then in the table it gives the option to choose only one flight to book. After selecting a certain flight by radio button and clicking "make booking for selected flight" button, the next page is required to display the flight details that have been selected from the previous page.
The problem is: how do I display the selected flight details?
I'm sure you did use the form for user to selected the appropriate options. Let's say:
<form action="nextpage.php" method="post">
<input type="radio" name="flight" value="flight1" />Option 1<br />
<input type="radio" name="flight" value="flight2" />Option 2<br />
......
<input type="submit" name="booking" value="Make Booking for the Selected Flight" />
</form>
Then on page nextpage.php you can get the flight that user have selected by using the php code below:
<?php
$flight = $_POST['flight'];
//do things u need here, for example
echo $flight;
?>
Pass some unique identifier from your flight to the details page via URL variable. To access those variables, simply use the PHP $_GET['id'] variable (in this case to access a url variable named id).
To pass an "id" url variable, simply append ?id=value to your redirect: http://page.com/details.php?id=5
Once you have this on your second page, it is very easy to do another MySQL query to retrieve the details from flight, say, 5 and display it on the second page.
You can use following method to send data on next page.
1) Session
2) Cookies
3) Get method
4) Post method(Using hidden fields).
Related
I have a php/mysql application in which I have a database broadly having the following fields:
Employee No.
Employee Name
Year of Joining
Location
Job Profile
I am able to display the records using the SELECT statement with no problem.
Now, I want to be able to do the following and this is where I need your help/suggestion on how to achieve it:
Select a few records randomly (using a checkbox or any other method suggested here) from the list of records displayed.
Have a button saying "Processed" on the screen. When I click on the button, the screen should refresh and the records selected in Step 1 above should be moved to another database and only the unchecked records should now be displayed.
Please let me know your suggestion on how to do the above.
Thanks
TS
For this you can use the id of the record, to get the information of the particular record using another single select query, and also can update the record with the id of the record. (create an edit link and pass the id, on edit page get the information with the id and save it.)
<?php //your db connection and select query here ?>
<form action="process.php" method="post" enctype="multipart/form-data">
<?php
// loop starts here
echo "<input type='checkbox' name='ids[]' value='".$row["id"]."' />";
// loop ends here
?>
<input type="submit" name="process" value="Processed"/>
</form>
This will create the checkboxes and on the process.php page
you can get the ids your need to process and can move your data
to other table/db where you want and after than redirect back to
to the page where your code is.
I'm attempting to create a form where the user is presented with a drop down list of options (the list will be to select a department in a company) and then once they have made their selection and hit submit, on the same page appears a new drop down list to select the member of staff. Those members of staff will only belong to the department that was selected. Once they have selected the member of staff and hit submit a new page can open with that member of staffs details.
The area I'm stuck on is how to make that second selection appear on the same page after the first selection has been done.
Here's the code I'm working with. This gets me my first drop down list where it pulls the list of departments from the relevant database table and populates the the drop-down. I need help with what to make the submit button do to get the next drop-down list:
<form action="<WHAT DO I PUT HERE?>" method="post">
<Name='deptselect'>
<select name="deptselect">
<?php
$SQL="SELECT name_of_dept FROM department where ID >= '1'";
$result = mysql_query($SQL);
while ($sqlrow=mysql_fetch_array($result))
{
$sqldept=$sqlrow["name_of_dept"];
echo "<option>
$sqldept
</option>";
}
?>
</select>
In HTML5, you can leave the action attribute off the form element and it will submit to the same page.
As for handling which step your user is in, probably recommend using a hidden form element tracking the actions. Something like this:
<form>
<!-- All other form data here -->
<input type="hidden" name="status" value="1">
</form>
Then you can just logically figure out/update the status as the user moves through the steps. Perhaps a simple switch statement to display appropriate drop down. Maybe like this:
switch ($_POST['status']) {
case 1: // Step 1 of the form
break;
case 2: // Step 2 of the form...and so on
break;
}
I have a db table 'order_form' and all records are displayed in a page.(I use dreamweaver.) In one of the records, contact no, i made a link Send SMS. If I click that,it should link to a page where i can send that number an sms.basically,the contact no should be displayed in the textfield and should match the one that belongs to the id num. How to do that?
The Send SMS link looks like this and it already displays the matching id num at the url. My probblem is binding the matching contact no which belongs to that id num. I hope I described it right.
<td>Send SMS</td>
After clicking Send SMS, it goes here and should display the matching contact no. in the Recepient textfield.
*NOTE i'm using transaction_num instead of id num.just to let you understand easily i used id num to ask here.
if the same table have the mobile no, say the field name is order_mobile_no, then change the Send SMS link code to the following:
<td>Send SMS</td>
and in the sending page, add this at the input of the mobile no field (recipient):
<input type ="text" name="xxx" id="xxx" value="<?php echo $_GET['order_mobile_no']?>" />
name and id = xxx, i am not sure what is that input is named.
EDIT:
to avoid that error, you need to check if that param is exist in the URL,
which is done using isset(), so the <input... tag should be :
<input type ="text" name="xxx" id="xxx" value="<?php if(isset($_GET['order_mobile_no'])){echo $_GET['order_mobile_no'];}else{echo "";}?>" />
i'm trying to parse the value of a textfield to my database.
The value inside my textfield is the ID of my product. When somebody presses the button "pin" it should send the value of the ID from that product to my database but the problem is it only sends value "5" because thats the first ID of my product list.
I do not know why it only takes the first value of my list of products.
When i look at the products on my page i can clearly see ID number 45 but even when i pin that product it sends value 5 to the database everytime.
I hope i'm not being too confusing.
Here is my php form and under that is the php page to send the data
<form id="myForm" action="insert/insertip.php" method="post" style="float:right;">
<input type="text" name="id" value="'. $row['id'] .'">
<input type="submit" value="Pin It" id="pin"></form>
$id = $_POST['id'];
$cookie = $_COOKIE['cookie'];
if(mysqli_query($con,"INSERT INTO pins(pinner, id_product) VALUES ('$cookie', '$id')"))
echo "successfully Inserted";
else
echo "insertion failed";
EDIT: Ill try to explain i little bit better, I have a whole list of products that i get from my database. Every product has a button under it to "pin" it. When somebody pins a product i send the ID of that product and the cookie of the user to my database. Everything works well exept when i try to send the ID of the product to my "pins" table it only sends the ID of my first product from the product table.
I dont know another way to send the ID of the product to the "pins" table than inside a textfield.
Maybe inside a span or use jQuery to put the value of the ID inside a variable and convert that variable to a PHP variable to send that value or something.
I also tried to use another name than "id" but it stays the same..
I'm trying to create a small web app that is used to remove items from a MySQL table. It just shows the items in a HTML table and for each item a button [delete]:
item_1 [delete]
item_2 [delete]
...
item_N [delete]
To achieve this, I dynamically generate the table via PHP into a HTML form. This form has then obviously N [delete]-buttons. The form should use the POST-method for transfering data.
For the deletion I wanted to submit the ID (primary key in the MySQL table) of the corresponding item to the executing php skript. So I introduced hidden fields (all these fields have the name='ID' that store the ID of the corresponding item.
However, when pressing an arbitrary [delete], it seems to submit always just the last ID (i.e. the value of the last ID hidden field).
Is there any way to submit just the ID field of the corresponding item without using multiple forms? Or is it possible to submit data from multiple forms with just one submit-button? Or should I even choose any completly different way?
The point why I want to do it in just one single form is that there are some "global" parameters that shall not be placed next to each item, but just once for the whole table.
<input type="submit" name="delete[1]" value="delete">
if (isset($_POST['delete'])) $id=key($_POST['delete']);
it seems to submit always just the last ID
It submits all of them, but since the name doesn't end with [], PHP discards all by the last.
Is there any way to submit just the ID field of the corresponding item without using multiple forms?
No. At least not without some unfortunate JavaScript. All (non-disabled) hidden inputs (with names and values) will be successful. You can't limit based on proximity to a clicked input element.
If I understand your goals correctly, you have two main options.
Put one form per row (in the cell with the delete button)
Encode the id value into the name of the submit button
You could get rid of the hidden fields and name your submit buttons like this:
<input type="submit" name="delete[1]" />
<input type="submit" name="delete[2]" />
<input type="submit" name="delete[3]" />
and then
<?php
if (isset($_POST['delete'])) {
$toDeleteId = key($_POST['delete']);
}