am fresh to coding, so please advice if i had done any mistake.
I am having 2 pages, one am using to input the value and the other need to display the value.i had created the input page with one text box and submit button, once i click submit button the text box content should go to the next page and display the value.
this is the second page where values should come and display
enter image description here
This is the first page am entering values
enter image description here, in this i had add one submit button
Kindly help and advice
thanks in advance
you can use session in php to do it, in the first php file:
session_start();
$_SESSION['var']=yourValue;
now in the second php file:
session_start();
echo $_SESSION['var'];
First write your form with with get method like
<form method="get" action="second.php">
<input name="text_field_name1" value=""/>
<input name="text_field_name2" value=""/>
</form>
than you form value pass second page with url.
You can get value from second page by echo $_GET['text_field_name1']; and echo $_GET['text_field_name2'];
Related
Firstly apologies. I am a complete novice. I wrote a small database over 10 years ago on whatever versions of php and mysql. I have managed to get the mysql piece working now but what I cant do is pass a variable from a selection page to another page.
I want to choose a location and that variable I assign categorynum as the variable. I then want to hit submit and it open up a second page that will use the value of categorynum in another mysql search. However it doesnt pass over. if i hardcode and declate categorynum as a value it works so I am guessing its the passing from page 1 to page 2
PAGE 1
<form method="get" action="page2.php">
<select name="categorynum">
<?php
foreach ($catByNum as $num=> $name){
print "<option value=\"$name\">$name</option>\n";
}
?>
</select>
<input type="text" name="categorynum" value="Submit">
</form>
Page 2
will pull in the word 'Submit' from the Value= piece (This is the wording that is on the button of the form on page 1 for submitting the choice)
Sorry if its really obvious
In your current page, change the name of your submit button <input type="text" name="categorynumSubmit" value="Submit"> then inside the second page (page2.php), use $_GET["categorynum"] to get the categorynum value
EDITS: Note that type="submit" not text
My php code in one page
<?php
if(isset($_POST['gonder'])){....}
if(isset($_GET['ozelid'])){.....}
?>
<input type="submit" name="gonder">
<td> <a href=\"?ozelid=YERTUTUCU&fiyat=$haskur\" onclick=\"return confirm('Tahsil Edilsin?')\" >Tahsil</a>
First time after the page loads ,when I click submit, it is okay and it only runs if(isset($_POST['gonder'])){....}
Again first time after the page loads , when I click the link then it only runs
if(isset($_GET['ozelid'])){.....}
However, after the page loads, when click the link and then I click the submit button both if(isset($_POST['gonder'])){....} and if(isset($_GET['ozelid'])){.....} run, which is not desired.
If you only want one of these being called at a time, then I would suggest just using an ElseIf.
<?php
if(isset($_POST['gonder'])){....}
Elseif(isset($_GET['ozelid'])){.....}
?>
You shoud check your form tag:
If you are using <form action="#" or keep the action attribute empty, the form is sent to the current page (in your case it's the page having the GET parameters).
Please check if you have the possibilty to set the action attribute of your form tag to something like this:
<form action="index.php" method="post">
You have to replace index.php with the name of your php file.
After you processed the request you can send location header. Like so:
header("Location: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
die();
To your current url without get parameters. I guess this should be in your code in this block:
if(isset($_GET['ozelid'])){.....}
I have a html page where the user can input some text, it is then posted to a php file and then stored in a database.
<form action="postphp.php" method="post" enctype="multipart/form-data">
<center><input id="postTitleStyle" type="text" name="title" size="100" maxlength = "180" ></center>
<center><textarea id="postTextStyle" name="Text" rows="10"cols="96" maxlength = "40000"><?php echo $text;?></textarea></center>
<center><input id="postTagStyle" type="text" name="tags" size="100" maxlength = "900" ></center>
<center><input type="submit" class = "Post2" value="post"></center>
</form>
Above is my current code for posting the data in the text field to a php file. I want to be able to click a button that when clicked will not go to the php file it will be stored and then when the user clicks the submit button it is posted. For example the user clicks it, a one is stored and then sent later when the user clicks the submit button after they are finished filling in other details. Is this possible?
P.S. I want to avoid Javascipt as much as possible for the moment, so if there is a non-java way of doing it then it would be much appreciated.
Many thanks, Jack.
There are two easy solutions to this problem without using Javascript. I'm assuming by your wording that you can currently post a form, but you don't know how to do so without leaving the current page. That's what I'll be answering below, but please note that there is no way to post a form without reloading at all without Javascript.
Solution 1: Put the PHP code into the same page the form is on and change the form tag to: <form action="" method="post" enctype="multipart/form-data">
A blank action field will cause it to run the PHP on the current page. You will likely need to look into using isset($_POST['submit']) in PHP, which will check whether the submit button has been clicked on before running that particular PHP code. You can read more about that HERE.
Solution 2:
In the postphp.php file that's currently linked to in your action field of your form, you could use a PHP header that will redirect the user after the PHP code is ran.
E.g.
<?php
{All your form processing code goes here}
header('location: my_form_page.php');
?>
In this example, my_form_page.php is the page on which your form is on. You can read more about headers in the answer of THIS question.
Hopefully this helps a bit.
$title = $_POST['title'];
$text= $_POST['text'];
$tags = $_POST['tags'];
mysql_query("INSERT INTO `table_name` (`colname1`,`colname2`,`colname3`) VALUES ('$title,'$text','$tags')");
$id = mysql_insert_id();
if($id){
echo "inserted";
}else{
echo "Not inserted";
}
For this you need to use Ajax (JavaScript will be used) because you need a button which send data to server without form submission and page reload it can be easily achieved using Ajax.
I have a page where the admin can see all the members who are registered, that means their information are stored in the database. It is in tabular form with Update links displayed beside each name which redirects to my update.php page with forms. After I click the Update link, I am redirected to my update.php and the URL displays the user id which I need to update :clinic/update.php?res_id=3
Now, I have a form in my update.php and I need to get that res_id=3 displayed in the URL to also be included in my MySQL INSERT STATEMENT in my action script which is add_assessment.php. I have tried using $ID=$_GET['res_id'] and $ID=$_POST['res_id'] but none of which is working. Can anybody please tell me what line of code do I have to use? Thanks
Without having any of your code to go by, I can only suggest stepping through your workflow and using var_dump on both $_GET and $_POST and making sure that the res_id is being passed from page to page.
You are not passing the value to the form so the $_POST or $_GET values on update.php will not be available to add_assessment.php.
In clinic/update.php?res_id=3 output $_GET['res_id'] as the value in a hidden form field like so:
<input type='hidden' name='res_id' value='<?php echo htmlspecialshars($_GET['res_id']); ?>' />
Then access it in add_assessment.php with $_POST['res_id']
OR
Append it to the action='add_assessment.php' in the form like so:
<form action='add_assessment.php?res_id=<?php echo htmlspecialshars($_GET['res_id']); ?>' method='post'>
Then access it in add_assessment.php with $_GET['res_id']
This is definately a novice question, but if you could be of any help i would be very grateful.
Basically, i'm building a database management page, and it of course includes a search function.
So, the search form looks something like this
<form name="name" function="search.php" method="get">
But, whenever i use it, i will of course get redirected to search.php. What i want is a way to display the results on the same page i did the search from (let's say index.php), without having to build an entire identical page around search.php
Thankful for answers.
Use a hidden field in the form that indicates that the form has been submitted.
In your form page (e.g. index.php)
<form name="name" action="index.php" method="post">
{OTHER_FORM_FIELDS}
<input type="hidden" name="doSearch" value="1">
</form>
So in your php code (could be in the index.php page or in a php script included)
<?php
if($_POST['doSearch']==1) {
//query database
//get results
} ?>
in your index.php page
<?php if($_POST['doSearch']) { //a search request was made display my search results ?>
HTML_CODE
<?php } ?>
Let the page submit to itself:
<form name="name" function="index.php" method="get">
In the handler for the page, check whether or not you have parameters and display either the input box or the results as appropriate.
You could even take it one step futher. You could use AJAX to insert the results directly into the page content when the submit button is pressed, rather than causing a page refresh.