Page 1 of 1

Invoking PHP page using Submit Button

Posted: Mon Sep 20, 2010 8:03 pm
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............

Re: Invoking PHP page using Submit Button

Posted: Tue Sep 21, 2010 4:51 am
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

Re: Invoking PHP page using Submit Button

Posted: Tue Sep 21, 2010 6:55 am
by ziaul1234
Can you please help me telling what function I can use in page.php
Thanks

Re: Invoking PHP page using Submit Button

Posted: Wed Sep 22, 2010 12:23 am
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