View Full Version : Appending variables to contact page

12-08-2010, 04:36 AM

I need help with appending variables to my php contact page. I have a php page with some products on it and would like the data sent to the textarea of the contact page when the inquire link is clicked. Could someone kindly provide the steps on doing this. Thanks.

12-08-2010, 04:45 AM
You can start by showing us the pages involved ... like a link to your website.
We need to see the products page and the contact page.

I have one question though,
Does the user go back and forth between the two pages and they can keep adding items to their inquiry?

12-08-2010, 04:51 AM
Hi, no the page doesn't involve a cart whatsoever, I would probably add that functionality later though. Here is the packages page that gets the stuff from the db.

<title>Kite Surfing Safaris</title>


<link href="../includes/css.css" rel="stylesheet" type="text/css" />
<body><marquee><div align="center" style="color:#ffffff; font-


<div id="kiteboarder"></div>
<?php include("menu_top.html"); ?>

<table width="640px" height="100%" align="center" valign="top" id="content"

border="0px"><tr><td valign="top"><div style="color:#ff9900; font-size:18px;"><h3

// Make a MySQL Connection
mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("products") or die(mysql_error());

// Get all the data from the "package" table
$result = mysql_query("SELECT * FROM package")
or die(mysql_error());

echo "<center><table border='1'>";
echo "<tr bgcolor='#ffff99'><th>Name</th> <th>Description</th><th>Price</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['p_name'];
echo "</td><td>";
echo $row['p_description'];
echo "</td><td>$";
echo $row['p_price'];
echo "</td><td><div><a href='#'>Inquire</a></div>";
echo "</td></tr>";


echo "</table></center>";

The following is the contact page

define("EMAIL", "youremail@yourdomain.com");

if(isset($_POST['submit'])) {


//assign post data to variables
$fname = trim($_POST['firstname']);
$lname = trim($_POST['lastname']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);

//start validating our form
$v = new validate();
$v->validateStr($fname, "first name", 3, 75);
$v->validateStr($lname, "last name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Contact Form Subject";
$email_to = EMAIL;

$emailMessage = "First Name: " . $fname . "Last Name: " . $lname . "\n";
$emailMessage .= "Email: " . $email . "\n\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$message_text = $v->errorNumMessage();

//store the errors list in a variable
$errors = $v->displayErrors();

//get the individual error messages
$fnameErr = $v->getError("first name");
$lnameErr = $v->getError("last name");
$emailErr = $v->getError("email");
$messageErr = $v->getError("message");
}//end error check
}// end isset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow"/>
<title>Kite Surfing Safaris</title>

<link href="../includes/css.css" rel="stylesheet" type="text/css" />

<div id="kiteboarder"></div>
<?php include("menu_top.html"); ?>

<table width="50%" height="100%" align="center" valign="top" id="content" border="0px"><tr><td valign="top"> <p><div style="color:#ff9900; font-size:18px;"><a href="mailto:sales@kitesurfingsafaris.com.au">sales@kitesurfingsafaries.com.au</a><br/>If you would like to inquire about our services please fill in the form below with your details and we will get in touch with you as quickly as possible.</div></p><br/>
<div id="contact_form_wrap"><fieldset><legend>Contact Us</legend>
<span class="message"><?php echo $message_text; ?></span>
<?php echo $errors; ?>
<?php if(isset($_GET['sent'])): ?><h2>Your message has been sent</h2><?php endif; ?>
<form id="contact_form" method="post" action="/contact3.php">
<p><label>First Name:<br />
<input type="text" name="firstname" class="textfield" value="<?php echo htmlentities($fname); ?>" />
</label><br /><span class="errors"><?php echo $fnameErr; ?></span></p>

<p><label>Last Name:<br />
<input type="text" name="lastname" class="textfield" value="<?php echo htmlentities($lname); ?>" />
</label><br /><span class="errors"><?php echo $lnameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>

<p><label>Message: <br />
<textarea name="message" class="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /></p>




12-08-2010, 04:58 AM
In response to your question earlier is that the better approach? I would just suggest the data that is retrieved from the db to sit in the textarea of the contact form then the user can add additional info if need be.

12-08-2010, 01:58 PM
This line:
echo "</td><td><div><a href='#'>Inquire</a></div>";

Will be:
echo "</td><td><div><a href='contact.php?inq={$row['p_name']}'>Inquire</a></div>";

Then, in contact.php, you'll get that variable


You can do whatever you want with it there.

12-08-2010, 10:35 PM
Hey mlseim I tried to get the value from the db to show in the textarea of the contact form but the php code gets output instead. This is what I get in the textarea of the form $inquiry=$_GET['inq'];> I have also wrapped the php tags around this bit of code

12-08-2010, 10:47 PM
It worked msliem, thanks bud.