Invoking PHP page using Submit Button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ziaul1234
Forum Newbie
Posts: 7
Joined: Thu Sep 16, 2010 4:52 pm

Invoking PHP page using Submit Button

Post by ziaul1234 »

Hi
Would be great if someone can help me.
I have created form in page1.html. User fill the form and can view it in page2.php where there is also an edit button.
If they need to edit any details, page3.php comes and they they can edit it. There is a confirm button on page3.php.

I have created another page4.php with commands to save the data in mysql.

Where I am stucked is, when user hit submit on page1.html, I need to page2.php to come and at the same time save those details to database using page4.php.
ANd
If user choose to edit, the data will be edited in mysql when confirmed button is pressed on page3.php.



I am giving a short coding for 3 pages:

Page 1: (HTML- FORM)
<html>
<body>
<form action="page2.php" method="post">
Name : <input type="text" name="name"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>


PAGE 2 (Displaying Input Values)
<html>
<?php session_start();?>
<body>
<form action="page3.php" method="post">
Name :<?php
$name=$_POST['name'];
$_SESSION['name']=$name;
echo $_SESSION['name']; ?>

<input type="Submit" value="Edit">
</form>
</body>
</html>

Page 3 (editing field with prefilled fields)

<html>
<?php session_start();?>
<head>
<?php
$name=$_SESSION['name'];
$discount=$_SESSION['discount'];
echo
"<form action=\"page4.php\" method=\"POST\">
Name :<input type=\"text\" name=\"name\" value=\"$name\"/> </br>
<input type=\"submit\" value=\"Confirmed\"/>";
?>
</body>
</html>

Thank you............
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: Invoking PHP page using Submit Button

Post by iijb »

Hi,

The code for saving data in mysql(ie, page4.php) just paste in page1.php(page1.html should be changed to php) along with the current code in page1.php. Also change the action in the form of page1.php . In page2.php you display the data from mysql.

Regards
iijb
ziaul1234
Forum Newbie
Posts: 7
Joined: Thu Sep 16, 2010 4:52 pm

Re: Invoking PHP page using Submit Button

Post by ziaul1234 »

Can you please help me telling what function I can use in page.php
Thanks
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: Invoking PHP page using Submit Button

Post by iijb »

Hi
In your page.php

Code: Select all

<?php
if(isset($_POST['btnSubmit'])) //name of your register button
	{
                    //your insert query here
               }
if(!$_POST) //if not post then show your form
		{
?>
//your html code of form here

<form name="form1" method="post" action="">
  <p>
    <label for="txtName">Name</label>
    <input type="text" name="txtName" id="txtName">
   <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit">
  </p>
</form>
<?php
}
?>
Hope this helps
Regards
iijb
Post Reply