dbmasters
10-14-2002, 11:43 AM
Include a file:
<?php include='filename.php'); ?>
DO NOT include a file with a URL, such as <?php include('http://www.domain.com/file.php'); ?> That slows down the servers down by having to start another web server instance for the request.
To print text inside PHP code:
<?php echo "Your text to print to the browser"; ?>
for HTML:
<?php echo "<p class="style" align"alignment">Your text to print</p>"; ?>
Note: The "" character before each quotation mark is an "escape" character so that the PHP parser prints the quote instead of thinking it is the end on the "echo" statement.
Passing querystring on a URL:
<a href="filename.php?var1=who&var2=where&var3=when">
On the following page that the links leads to you have the following variables available to you:
$var1 has a value of "who"
$var2 has a value of "where"
$var3 has a value of "when"
Of course, you can replace var1, var2 and var3 with anything you wish, just don't use spaces.
Passing form data:
Example <input type="text" name="field_name"> would be available on the page the form is submitted to as $field_name. It works the same with any field type.
$PHP_SELF will give you the name of the file you are on including it's path from the webroot.
Therefore, to pass a form to itself you would code the form tag as follows:
<form method="post" action="<?php echo $PHP_SELF; ?>?action=submit">
Then make sure the page was the following conditional loop:
<?php
if($action=="submit")
{
the code you want to run with the submitted form data be it emailing it, submitting it to a database or whatever
}
else
{
add your form in here including the above form tag to submit it to itself
}
?>
Mail function:
<?php mail("recipients email addy","subject of email","body of email","From: from email addy"); ?>
I hope this answers a few of the basic questions some may have about PHP. Obviously there is MUCH more than this though...
<?php include='filename.php'); ?>
DO NOT include a file with a URL, such as <?php include('http://www.domain.com/file.php'); ?> That slows down the servers down by having to start another web server instance for the request.
To print text inside PHP code:
<?php echo "Your text to print to the browser"; ?>
for HTML:
<?php echo "<p class="style" align"alignment">Your text to print</p>"; ?>
Note: The "" character before each quotation mark is an "escape" character so that the PHP parser prints the quote instead of thinking it is the end on the "echo" statement.
Passing querystring on a URL:
<a href="filename.php?var1=who&var2=where&var3=when">
On the following page that the links leads to you have the following variables available to you:
$var1 has a value of "who"
$var2 has a value of "where"
$var3 has a value of "when"
Of course, you can replace var1, var2 and var3 with anything you wish, just don't use spaces.
Passing form data:
Example <input type="text" name="field_name"> would be available on the page the form is submitted to as $field_name. It works the same with any field type.
$PHP_SELF will give you the name of the file you are on including it's path from the webroot.
Therefore, to pass a form to itself you would code the form tag as follows:
<form method="post" action="<?php echo $PHP_SELF; ?>?action=submit">
Then make sure the page was the following conditional loop:
<?php
if($action=="submit")
{
the code you want to run with the submitted form data be it emailing it, submitting it to a database or whatever
}
else
{
add your form in here including the above form tag to submit it to itself
}
?>
Mail function:
<?php mail("recipients email addy","subject of email","body of email","From: from email addy"); ?>
I hope this answers a few of the basic questions some may have about PHP. Obviously there is MUCH more than this though...