PHP Variables between Scripts


 

PHP Variables between Scripts

PHP Variables between Scripts.As you know how to define variables and how to use them in your form. Now, we learn how to use PHP variables between scripts. It is quite similar as using variable in a normal manner.

PHP Variables between Scripts.As you know how to define variables and how to use them in your form. Now, we learn how to use PHP variables between scripts. It is quite similar as using variable in a normal manner.

PHP Variables Between Scripts

As you know how to define variables and how to use them in your form. Now, we learn how to use  PHP variables between scripts. It is quite similar as using variable in a normal manner. Let see the example and you will understand easily. Here, we create an E-mail form using php variables.

Page_1(emailform.php)

<html>
<head>
    <title>Email Form</title>
</head>
<body>
    <form method="post" action="sendmail.php">
    <table width="500" align="center" cellpadding="4" cellspacing="4" border="1">
        <tr>
            <td> Email:</td>
            <td><input name="email" type="text" /></td>
        </tr>
        <tr>
            <td> Subject:</td>
            <td><input name="subject" type="text" /></td>
        </tr>
        <tr>
            <td> Message:</td>
            <td> <textarea name="message" rows="15" cols="35"></textarea></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" /></td>
        </tr>
    </table>
    </form>
<body>
</html> 

Here, we just create a simple e-mail design.

 

Page_2(sendmail.php)

?php
session_start();
$a['email'] = $_POST['email'];
$a['subject'] = $_POST['subject'];
$a['message'] = $_POST['message'];

$_SESSION['login'] = $a;

mail( "[email protected]", "Feedback Form Results",
$a, "From: $a" );
header( "Location:message.php" );

?>

Here, in this page we declared variable and used array or session variable to show the message into other page. In the next line we use mail( ) function, which is the most important part of this tutorial. In the mail function we use the syntax mail(to,subject,message,from) and we make an array to those variable and used in our code. After that we passed the header( ) of the third page.

Page_3(message.php)

<?php
session_start();
$abc = $_SESSION['login'];
foreach($abc as $key=>$value)
{
echo " $key."---->".$value."<br/>";
}
?>

Also in this we used variables between script to show the email message. The output of the project is:

email---->[email protected]
subject---->Hi how r you?
message---->Everything is fine! What about you?

 

 

Ads