Hi,
I have an insert page which works - but i want to validate it and not sure how to...i also want to ask a question such as "what color is the sun?" to see if it's a human filling in the form. so basically if color does not = yellow please fill in the form again type thing.
<?php require_once('Connections/myconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "contact")) {
$insertSQL = sprintf("INSERT INTO Alabama (Name, Email, Restaurant, Website, `Description`, URL) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['restaurant-title'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['url-to-link-to'], "text"));
mysql_select_db($database_myconn, $myconn);
$Result1 = mysql_query($insertSQL, $myconn) or die(mysql_error());
$insertGoTo = "thanks.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/restaurant-articles.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Advertise your restaurant for free</title>
<!-- InstanceEndEditable -->
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style/usa.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
<h1><a href="#">foo-bar.com</a></h1>
<p> </p>
</div>
<div id="menu">
<ul>
<li><a href="http://www.foo-bar.com/index.html">Home</a></li>
<li><a href="http://www.foo-bar.com/restaurant-articles/index.php">Restaurant Articles</a></li>
<li><a href="http://www.foo-bar.com/recipes/index.php">Recipes</a></li>
</ul>
</div>
</div>
<!-- end header -->
<div id="headerbg" align="center"><span style="white-space: nowrap" margin-top: "20px"><img src="images/restaurant.jpg"><img src="images/food.jpg"></span></div>
<!-- start page -->
<div id="page">
<!-- start content -->
<div id="content"><!-- start latest-post -->
<!-- InstanceBeginEditable name="body" -->
<div id="latest-post" class="post">
<h1 class="title">Advertise your restaurant for free</h1>
<div class="entry">
<p>Fill in your details - and your information will be added to the relevant page for all to see.</p>
<p><?php echo $error ?></p>
<form name="contact" action="<?php echo $editFormAction; ?>" method="POST" id="contact">
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="tableindent">
<tr>
<td><div align="right">Your Name:</div></td>
<td><input name="name" type="text" id="name" /></td>
</tr>
<tr>
<td><div align="right">Email:</div></td>
<td><input name="email" type="text" id="email" value="" /></td>
</tr>
<tr>
<td align="right" valign="top">Restaurant title:</td>
<td><input name="restaurant-title" type="text" id="restaurant-title" value="" />
(anchor text of link) </td>
</tr>
<tr>
<td align="right" valign="top">URL to link to: </td>
<td><input name="website" type="text" id="website" value="" />
<br />
(e.g. my-restaurant.com - do not include http or www.) </td>
</tr>
<tr>
<td align="right" valign="top">description:</td>
<td><textarea name="description" id="description" cols="45" rows="5"></textarea>
<br />
(up to 1000 words) </td>
</tr>
<tr>
<td><div align="right">URL you want to advertise on: </div></td>
<td><input name="url-to-link-to" type="text" id="url-to-link-to" value="<?php echo $_SERVER['HTTP_REFERER'];?>" size="40" readonly="true" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="submit" value="Submit Message" /></td>
</tr>
</table>
<p>The anchor text is the wording you wanted highlighted in blue as your link. </p>
<input type="hidden" name="MM_insert" value="contact" />
</form>
<p><!-- end latest-post -->
<!-- start recent-posts -->
</p>
</div>
</div>
<!-- InstanceEndEditable -->
<!-- end latest-post -->
<!-- start recent-posts -->
<div id="recent-posts">
<div class="post">
<h2 class="title">Restaurant Article</h2>
<!-- InstanceBeginEditable name="restaurant-article" -->
<div class="entry">
<p>How to open a successful restaurant..</p>
<p><a href="restaurant-articles/how-to-open-a-successful-restaurant.php" class="more">Read more</a></p>
</div>
<!-- InstanceEndEditable --></div>
<div class="post">
<h2 class="title">Recipe</h2>
<!-- InstanceBeginEditable name="recipe" -->
<div class="entry">
<p>A better pot roast..</p>
<p><a href="http://www.foo-bar.com/recipes/a-better-pot-roast.php" class="more">Read more</a></p>
</div>
<!-- InstanceEndEditable --></div>
<div class="post">
<h2 class="title">Restaurant Business Plan</h2>
<!-- InstanceBeginEditable name="business-plan" -->
<div class="entry">
<p>Italian Restaurant Business Plan </p>
<p><a href="http://www.businessplanning-4-you.com/business-plans/Italian-Restaurant-Business-Plan.html" target="_blank" class="more">Read more</a></p>
</div>
<!-- InstanceEndEditable --></div>
</div>
<!-- end recent-posts -->
</div>
<!-- end content -->
<!-- start sidebar -->
<div id="sidebar">
<ul>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
<div style="clear: both;"> </div>
</div>
<!-- end sidebar -->
</div>
<!-- end page -->
<div id="footer">
<p id="legal">©2008 All Restaurants USA. All Rights Reserved.</p>
<p id="links"><a href="http://www.foo-bar.com/index.php">Home</a> | <a href="http://www.foo-bar.com/terms.php">Terms</a> | <a href="http://www.foo-bar.com/faq.php">FAQ</a> | <a href="http://www.foo-bar.com/contact.php">Contact Us</a></p>
</div>
</body>
<!-- InstanceEnd --></html>