I am working on a restaurant search and review project. I have a search page that will show restaurant names and provides a link for the user to add a review for each restaurant result by using the hidden input rid.
In my review.php, I am using the value sent in for the hidden input rid to run another simple query and then display the name of the restaurant. Then I have several inputs so the user can input their name, their rating of the restaurant, and finally a comment.
<form action="comment.php" method="GET">
<INPUT TYPE="hidden" NAME="rid" VALUE="">
<?php
$db=mysqli_connect(//parameters);
$restaurant_id= $_GET['rid'];
if (!empty($_GET)){
$result = $db->query(//query);
$row = $restaurant_result->fetch_assoc()
echo $row["name"];
}
?>
<INPUT //other inputs for the user>
</form>
My problem is that when the user hits a submit button at the bottom, the page will refresh with the url www..../review.php?rid= meaning that the name of the restaurant can't be displayed since no restaurant id parameter is being resent in the form. How can I send the restaurant id back to the page again once it is done?
I tried the top answer in this thread but I get the same url problem: Pass parameter to form action in HTML
<INPUT TYPE="hidden" NAME="rid" VALUE="<?php if(isset($_GET['rid'])){echo $_GET['rid'];} ?>">
Related
I have 2 forms right now. Form A, where I display the value inserted by user. (a user can insert as many value as they want). That's the reason why I put the radio button because at the end they need to choose only one to proceed. I have a button to save what a user has inserted.
Form B, where I have a button to go to another page that brings the value form the chosen radio button.
at formA.html
<form method="POST" action="formB.php">
<--your radio buttons goes here-->
<input type="submit" name="formAsubmit">
</form>
at formB.php
<?php
if(isset($_POST['formAsubmit'])){
//print user entered values on form A
?>
<form action="formB.php" method="POST">
<--your form B input fields goes here-->
<input type="submit" name="formBsubmit"/>
</form>
<php?
} elseif (isset($_POST['formBsubmit'])){
//Do what you want with formB informations
}
?>
Thats your dual forms
I have a live search form on the site that does two things. If it gets any results it displays them, and if not, the visitor can send an email.
There are two input type fields
<input type="hidden" name="myField" id="myField" value="" />
Email: <input name="email-index" id="email-index" type="text" /></b>
In the email field, the visitor inputs the email. And in the value of the hidden field, i want the search query to be passed from the query.
The search query results are displayed one div before this form with
<!-- Results -->
<h4 id="results-text"> <b id="search-string"></b></h4>
where search-string is replaced with the query.
I have put this into jquery
var hidden = "search-string";
$('input[name=myField]').val(hidden);
but nothing really happens, i get an empty output.
Thank you for your help!
If you have $_GET['search-query'] parameter, just output it to input field:
<input type="hidden" name="myField" id="myField" value="<?php echo $_GET['search-query']; ?>" />
It is because you do not actually get anything from jquery.
Change your script to:
var hidden = $("#search-string").text();
$('input[name=myField]').val(hidden);
<form action="" method="post">
Name : <input type="text" name="fname"/><br/>
Activities :
<?php
$sql_activities = "select * from tb_activities";
$query_activities = mysql_query($sql_activities);
$active = 1;
while($row_activities = mysql_fetch_array($query_activities)) {
?>
<input type="checkbox" value="<?=$row_activities['activity_id'];?>" name="activities<?=$active;?>"/>
<?=$row_activities["activity_name"];?>
<?php
$active++;
}
?>
<input type="submit" value="Save" name="save" />
</form>
Here is my form. Now in this form I am saving two fields name and activities, suppose I entered a name and I choose five activies that are coming from a table, suppose I choose five activities, at the time of insertion I am sending IDs of the activities in the table but not the activity name. My problem is that at the time of editing I want to show the activity names that the user chooses. How to show the names of the activities that the user have chosen? Can anyone help me?
you are not clear.i think you are new to php and asking about sql join statement.http://www.w3schools.com/sql/sql_join.asp
If I'm understanding the question correctly (and I may not be) if you change your checkbox to:
<input type="checkbox" value="<?php echo $row_activities['activity_id']; ?>"
name="activitiesChosen[]" >
Then when you submit your form you will pass an array (activitiesChosen) that contains all the visitors choices (as activity IDs).
Then, when you want to display the choices you get the array from the database and just use the php in_array command to see if they have chosen that activity.
i am retrieving data form database using a search query.
PHP code (which I'm using in search query to display search results)
echo "<span style='background-color= #FFFF00'>$query</span><br>";
$count=$dbo->prepare($query);
$count->execute();
$no=$count->rowCount();
if($no > 0 ){echo " <span>No of records = ".$no."</span>";
echo "<table><tr><th>PHONE NUMBER</th><th>OWNER NAME</th></tr>";
foreach ($dbo->query($query) as $row){
echo "<tr><td>$row[ROLLNO]</td><td>$row[CNAME]</td></tr>";
}
echo "</table>";
i want to do like this,
when a user clicks on a phone number, it should redirect to a new page and in that new page, my input box should be filled with this phone number and should be submitted.
Input Box Code (which I'm using in page 2)
<form name="phone_number_form" id="phone_number_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return vali()" >
<input type="text" name="number" id="number" />
<input type="submit" name="submit" value="Submit" />
</form>
Looking at w3schools PHP has a $_POST variable which is used to collect values from a form sent with method="post". There's also $_GET and $_REQUEST which seems to merge both post and get data. http://www.w3schools.com/php/php_post.asp
There are a couple of options like making a request (get) from your first page or post the data from your first page.
REQUEST Method
Heres how I think the request way to do it would work
PAGE 1
Amend the foreach that renders the table row to include an hyperlink to your second page
foreach ($dbo->query($query) as $row){
echo "<tr><td>$row[ROLLNO]</td><td>$row[CNAME]</td></tr>";
}
PAGE 2
Amend the textbox to be populated with the phone number from the request variable
<input type="text" name="number" id="number" value="<?php echo $_REQUEST["phoneno"]; ?>" />
POST Method
In your first page using javascript when the user clicks the phone number set a hidden field and submit the form to the second page. Again you should be able to read the hidden fields value from the $_REQUEST variable
I have a form like this :
$form = '<form action="https://www.zarinpal.com/users/pay_invoice/'.$res.'"
method="post" target="_parent" ><input type="submit" value="Buy"/></form>';
$form .= '</form>';
echo $form;
I want to add a function to this form, so when "Buy" is clicked, then in MySQL a database is created for this user with the information of the selected item and his account id with a pending transaction status, and then the form redirects him to the webpage included.
I can manage the MySQL part, but the form only redirects the user to the given webpage, and i can not add users information to the database.
Is there a way I can add a database row for this user, then redirect him to the payment webpage ? ( except creating another page )
<form action="https://www.zarinpal.com/users/pay_invoice/<?=$res ?> method="post" target="_parent" >
<input type="test" name="customer-name" />
<input type="submit" value="Buy"/>
</form>
Then on the target page put:
<?
print_r($_POST);
## That will let you know what is being posted from the form
?>
To access the 'customer-name' variable for example just do:
$customerName = $_POST["customer-name"];