Welcome to PCCS-Linux.COM Hello, and welcome to the PCCS-Linux Home Page.
Your last visit was !!!
Your Browser is running on Other
 
Mail Functions
PHP Functions: You are allowed to define you own or use some of PHP's
built in functions

// Lets look at the code below;
// We will begin the coding for our php feedback form application.

// We will define some variables and create our own function as well as
use some of the built in 
// functions available to PHP to be used by our program.

// Using the variables defined above, we will complete the required
variable needed by the;
// mysql_connect mysql_pconnect functions to connect to our database.

$f = mysql_pconnect("$db_server","$db_user","$db_passwd") or die("Sorry
The Database is Currently Down");

// Define a variable for debugging our application

$debug_queries=0;

// Here we will create a function that will process our SQL queries and
handle the debugging if the value 
// of $debug_queries=1

function mysqlquery($db_name,$query)
        {
          global $verbose_queries;
          if ($debug_queries!=0)
                echo $query."<BR>";
          $result = mysql($db_name,$query);
          return $result;
        }
// Function to create a blank space ... used to display data

function print_fld($val)
{
        $val = chop($val);
        if ($val != "")
          print $val;
        else
          print " ";
}

// Here we will create a variable and pass it to our function mysqlquery
// This section of the code will be used to insert data into the DB TBL

$comments = addslashes($comments);
$query = "INSERT INTO $tablename (
                        id,
                        name,address,
                        email,city,
                        state,zip,
                        foundus,youlike,
                        comments,ipaddr) 
               VALUES (
                        '',
                        '$name','$address',
                        '$email','$city',
                        '$state','$zip',
                        '$foundus','$youlike',
                        '$comments','$ipaddr')";

$res = mysqlquery($db_name, $query);
        if(!$res) {
        // Do nothing because data was entered
        } else {
        echo mysql_error() . "<BR>\n";
        }

// Here we will create a variable and pass it to our function mysqlquery
// This section of the code will be used to Display data from the DB 
// We will also intergrate HTML to display data from DB

$showall_qry = "SELECT * from $tablename ORDER BY $order_by
$res = mysqlquery($db_name, $showall_qry)
                if(!$res) {
                //
                } else {
                        echo mysql_error() . "<BR>\n";
                }
$num = mysql_numrows($res);

print "
<TABLE BORDER=1 CELLSPACING=2 CELLPADDING=0>
<TR>
<TH>Name</TH>
<TH>Address</TH>
<TH>Email</TH>
<TH>Address</TH>
<TH>City</TH>
<TH>State</TH>
<TH>Zip</TH>
<TH>Where</TH>
<TH>Like Site</TH>
<TH>IPAddress</TH>
</TR>
";

for ($i=0; $i < $num; $i++):
print "<TR>";

$par = mysql_result($res, $i, "id");

print "<TD>";
$val = mysql_result($res, $i, "name"); 
print "<A HREF=\"$scriptname?action=display&par=$par\">";
print_fld($val); 
print "</a>";
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "address"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "email"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "address"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "city"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "state"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "zip"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "foundus"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "youlike"); print_fld($val);
print "</TD>";

print "<TD>";
$val = mysql_result($res, $i, "ipaddr"); print_fld($val);
print "</TD>";

endfor;

print "</TR>";
print "</TABLE>";
// End of Display Code


// This function will display feedback form 

function display_feedback_form() {
global $scriptname;
?>
<html><head><title>My Feedback Form</title>

</head>
<body bgcolor='white'>
<form action="<? echo
"$scriptname?action=process" ?>" method='post'>
<table>
<tr>
<td> Name: </td> <td> <input type='text' name='name'
size='30'></td>
</tr>
<tr>
<td> Address: </td> <td> <input type='text'
name='address' size='35'></td>
</tr>
<tr>
<td> Email: </td> <td> <input type='text'
name='email' size='20'> </td>
</tr>
<tr>
<td> City: </td> <td> <input type='text' name='city'
size='15'> </td>
</tr>
<td> State: </td> <td> <input type='text'
name='state' size='2'> </td>
</tr>
<tr>
<td> ZIP/Postal Code: </td> <td> <input type='text'
name='zip' size='5'> </td>
</tr>
<tr>
<td> Where did you find us? </td>
<td>
<select name='foundus'>
<option value='searchengine' selected>Search Engine</option>
<option value='newsgroups'>UseNet</option>
<option value='ad'>Advertisement</option>
</select>
</td>
<tr>
<td> Did you like our site? </td> 
<td> 
<input type='radio' name='youlike' value='yes' checked> Yes
<input type='radio' name='youlike' value='no'> No
</td>
</tr>
<tr>
<th colspan=2 align=left> Comments: </th>
</tr>
<tr>
<td colspan=2> <textarea name='comments' cols='70'
rows='10'></textarea></td>
</tr>
<tr>
<td>
<input type='submit' name='submit' value='Submit'>
<input type='Reset' name='reset' value='Reset'>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
}
// End display_feedback_form()

// Variables that will be used with the PHP email function of our feedback
form

$mailto="cthorn@localhost";
$mailsubject="Form Reply from $name";
$mailbody="Name of Individual:\t $name\n\n";
$mailbody .="Email address:\t $email\n";
$mailbody .="Address:\t $address\n";
$mailbody .="City:\t $city ";
$mailbody .="State:\t $state ";
$mailbody .="ZIP:\t $zip\n";
$mailbody .="Where found: $foundus\n";
$mailbody .="Did they like the site?:$youlike\n\n";
$mailbody .="Comments:\n$comments";
$mailheaders="From: $email";

function send_email() {
global $mailto, $mailsubject, $mailbody;
//send mail
mail($mailto, $mailsubject, $mailbody,
$mailheaders);
}

send_email();
// End Email Code 

// Now we will create a mixture of HTML and PHP code to display a record
// Again we will define variables and use the mysqlquery function we
created
// earlier. We also use another on of PHP's MySQL functions mysql_result

$query = "SELECT * FROM $tablename WHERE id =$par";
$res = mysqlquery("$db_name", $query);

print "
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2>

<TR>
<TD valign=top><B>Name :</B> 
<TD> ";
echo mysql_result($res, 0, "name");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>Address :</B> 
<TD> ";
echo mysql_result($res, 0, "address");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>E-mail :</B> 
<TD> ";
echo mysql_result($res, 0, "email");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>City, State Zip :</B> 
<TD> ";
echo mysql_result($res, 0, "city") .",  ";
echo mysql_result($res, 0, "state") ."  ";
echo mysql_result($res, 0, "zip");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>Where Did you find us :</B> 
<TD> ";
echo mysql_result($res, 0, "foundus");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>Did you like our site :</B> 
<TD> ";
echo mysql_result($res, 0, "youlike");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>Comments :</B> 
<TD> ";
echo mysql_result($res, 0, "comments");
print "
</TD>
</TR>

<TR>
<TD valign=top><B>Submitters IP :</B> 
<TD> ";
echo mysql_result($res, 0, "ipaddr");
print "
</TD>
</TR>
</TABLE> ";

>> Comments/FeedBack


Page hits 62 last request on :11:30



This web site is prepared and maintained by Chauncey Thorn.
The information contained in this site was valid at the time of posting.
Chauncey Thorn, assumes no liability for damages incurred directly or indirectly as a result of errors, omissions or discrepancies.

Remember most of the content here are my notes...

All logos and trademarks in this site are property of their respective owner. All the rest © by PCCS-Linux.COM

PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002