need help in PHP code
Posted by: hubby4u (---.edu.pk)
Date: September 09, 2014 10:52AM

i want to add two text boxes and a Submit button to a HTML form and Invite the user to enter a first name and surname. When the button is clicked, i want to display the first name and surname in the textboxes using php code.

note: html and php are in the same file named exercise1.php.



Edited 2 time(s). Last edit at 09/09/2014 11:54AM by hubby4u.

Options: ReplyQuote
Re: need help in PHP code
Posted by: Otomatic (Moderator)
Date: September 09, 2014 11:16AM

Hi,

[www.w3schools.com] Chapter PHP Forms
[myphpform.com]

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: need help in PHP code
Posted by: ruthermelchor (---.79.199.112.clbrz.inet.eastern-tele.com)
Date: September 10, 2014 05:31AM

Are you going to use this as it is or with the WAMP server as your backend?

If you are going to use this without a backend(Database) to store and retrieve your date, you can use the super global variable $_SESSION. You will going to need to create a new .php page where your will be redirected and set your data from your textboxes on the Session variable.: IE (note that you have to start SESSION first and unset the variables first before adding new data into it, this is if you want it to work multiple times.)

session_start();
$_SESSION["Firstname"] = $_POST['firstname'];
$_SESSION["Lastname"] = $_POST['lastname'];

After this, you will want to redirect it back to your original page. IE:

header("Location: originalpage.php"');

Then at your original page, you can print them using the global variable you just set. IE:

echo "Your first name is".$_SESSION["Firstname"] .";
echo "Your last name is".$_SESSION["Lastname"] .";

If you are going to use this with a backend(Database) you will use the insert and select SQL commands. First, you will need to insert your data in the database and then select it on the page where you want to display it. IE: (Note that ínsert into will only work if you are to use this once, if you want it to work multiple times, you will need to create a 'rouge' data in the database and then just change insert to update) :

$con=mysqli_connect("localhost","root","","dbJobsheets"');
mysqli_query($con,"INSERT INTO YOURTABLE (COLUMN1, COLUMN2) VALUES ('VALUE1', 'VALUE2')"');

And then select and print it in you original page. IE:

$result=mysqli_query($con,"SELECT * FROM YOURTABLE"');
echo "Your first name is".$row["COLUMN1"].";
echo "Your last name is".$row["COLUMN2"].";

*I added some single quotations before the doubles to prevent it from displaying a smiley.
This are just examples that you can use; Good luck on your page!



Edited 3 time(s). Last edit at 09/10/2014 05:53AM by ruthermelchor.

Options: ReplyQuote


Sorry, only registered users may post in this forum.