Using PHP to change pages content - php

I have a few pages, PAGE 1 is an input form that allows accesed users to change PAGE 2/3 etc.... I am hoping to use PHP to do this but im not too PHP savvy.
Scenario
Page 1 has two drop down menus that are made in HTML (master page) the first has the persons name "Mike" & "Jim" and the second contains a score from 0 to 10. I want that if i select mike and 7 and then click submit, it will update page 2 (mikes page) and display "Mike" & "7" and then if i click "Jim" & "3" it will update jims page to display Jim and 3
How will i most efficiently go about doing this? preferably simple PHP if its possible.
All these pages + scripts will be on a server & i know jscript only is client side meaning it cannot change another page.
Any help is greatly appreciated

you can achieve this by creating sessions. for example, there i have taken 2 pages and sending data from input field of one page to another
page1.php
<?php
session_start(); //this must be the first line in php page
$_SESSION['variable']=$_POST['anything']; // this will save value from input tag in form in session.
header( "Location: page2.php" );
?>
<html>
<head>
<title>Session</title>
</head>
<body>
Welcome to page 1.
<br/>
<br/>
<form method="post" action="page1.php"> // this will call page2.php on button click
Type anything
<input type="text" name="anything" />
<input type="submit" value="Send value to page 2" />
</form>
</body>
</html>
page2.php
<?php
session_start();
echo $_SESSION['variable'];
?>

Related

How to get php to pass a variable to a second page

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

need to paas value from one page to another in php

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'];

PHP - How to send values in Multiple pages Form

So, I was working on a PHP Application Center (Form), and I'm stuck at something.
I have 3 pages of form and 1 sumbit page. All are in .php extention. So, I want to take the <input name="name" type="text" placeholder="Name" required> from page one and:
<label>About yourself (Atleast 50 Words): <span>*</span></label><br />
<textarea name="yourself" placeholder="About yourself (Atleast 50 Words)" ></textarea> to the submit page.
I can take the values of Textarea & Textbox from page 3 to submit page through <?php echo $_POST['somethinghere']?>. But I can't take values from the First and second page.
Here are links to my php codes with style.css (pastebin.com):- http://pastebin.com/81vgHh5H
I had a look at the Pastebin and I think I can see the problem. You're setting the Session data on the same page that they're filling out (so you're assigning those fields to the session before they've even been filled in). You need to do that on page 2, not page 1. So your pattern is thus:
Show page 1 form.
User fills it out and hits submit.
Send user to page 2.
Page 2 grabs the information posted from Page 1, stores it in the session.
Page 2 shows the second form page.
User fills out page 2 and hits submit.
Send user to page 3.
Page 3 grabs the information posted from Page 2, stores it in the session.
And so on...
By the time you get to the last page, your session will contain all the information from the form and you can then process it however you need to.
Example:
Page 1:
<form action="page2.php">
<input type="text" name="page1text"/>
<input type="submit"/>
</form>
Page 2:
<?php
$_SESSION['page1text'] = $_POST['page1text'];
?>
<form action="page3.php">
<input type="text" name="page2text"/>
<input type="submit"/>
</form>
Page 3:
<?php
$_SESSION['page2text'] = $_POST['page2text'];
?>
<form action="page4.php">
<input type="text" name="page3text"/>
<input type="submit"/>
</form>
Page 4:
<?php
$_SESSION['page3text'] = $_POST['page3text'];
?>
<ul>
<li>Page 1: <?php echo $_SESSION['page1text'] ?></li>
<li>Page 2: <?php echo $_SESSION['page2text'] ?></li>
<li>Page 3: <?php echo $_SESSION['page3text'] ?></li>
</ul>
As you can see, page 4 winds up with access to all of the information from the previous pages.
Edit: This answer previously read: I would recommend having a model that contains all of the form's properties. As they fill out each page, populate the model with the data the user has entered and then when they successfully complete the form you can destroy the session data.
You can store them in session like, pass your data from page one to page two and in page two do following
$_SESSION['name'] = $_POST['name'];
Again, pass your data from page two to page three and in page three do following
$_SESSION['yourself'] = $_POST['yourself'];
This will set your name and yourself data in session and will be accessible from any page. Do not forget to include session_start() at the top of your page if that page uses session.
Now, you can access those session variable from submit page like,
echo $_SESSION['name'];
echo $_SESSION['yourself'];

submit a form with a link from another page

I have created 3 php pages. The 1st includes the following form:
<form method="POST" name="go" action="search_form_all.php" >
<input name="value" type="text" id="search_form_1" size="65" placeholder="enter name"/>
<input type="submit" value="" name="submit" />
</form>
The 2nd page called "search_form_all.php" includes the php codes that displays the results of the above form. So if the user type a name in form and press submit, the "search_form_all.php" displays all names from my database according to what the user inserts in the search form.
All I want is to have in my 3rd php page a link, that when the user press it to execute the form in 1st page. For example if I enter a name in search form like "john", then I want to be able to go to my third page and press the link, the form to be executed and to return all names "john" from my database. Is this possible?
Yes, this is possible with session variables. An example:
<?php
session_start();
if(isset($_SESSION['views'])) {
$_SESSION['views']=$_SESSION['views'];
} else {
$_SESSION['views']=1;
}
echo "Views=". $_SESSION['views'];
?>
You can also refer to Document Link
Let me know if you need more help.

Post information from 1st page to 3rd page

I need to consider something in the future after I finish my application. What is going to happen is that a teacher will need to first login (login page is page 1), after login the page will go straight to a menu where the teacher selects a hyperlink link to open up a page (hyperlink menu is page 2), On third page I want a message displaying welcome to the teacher who has accessed the page (page 3 is welcome page).
Is there a way to get the teacher username from page 1 and displaying it on page 3 is what I am asking?
Below is coding and example:
Page 1: InputTest.php
<body>
<form action="InputTest2.php" method="post">
<p>Please enter your name</p><p><input type="text" name="user" /></p>
<p><input type="submit" value="Send" /></p>
</form>
<!-- The above allows a name to be entered and submitted to "InputTest2" by clicking on send button -->
</body>
Page 2: InputTest2.php
<body>
<p>Welcome</p>
<p>...</p>
<p>...</p>
</body>
Page 3: InputTest3.php
<body>
<?php print "Welcome <b>".$_POST['user']."</b><br/>\n"; ?>
</body>
in your InputTest2.php
add the following code in the start of the page
session_start();
$_SESSION['usernameLogged'] = $_POST['user'];
and then you can print it like this
also you should start a session
<?php
session_start();
print "Welcome <b>".$_SESSION['usernameLogged']."</b><br/>\n";
?>
Save it in the $_SESSION superglobal.
$_SESSION['user'] = $_POST['user'];
Then $_SESSION['user'] will be available on the third page.
Note: you will need to have session_start(); on both pages in order to store/retrieve session data like that.
Possible duplicate of: php: Save the entire $_POST variable in the session

Categories