I'm doing a tutorial in Dreamweaver SC3, where the contents of a form are auto stored in a database. On the first trial the info I wrote in the form was passed to the database successfully. But on further runs I get an error message "The connection was reset during loading please try later"
Can anyone help and show me where I'm going wrong.
I'm using an internal browser, firefox, and apache.
Terry
- Code: Select all
<?php virtual('/terry/Connections/connAdmin.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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO feedback (name, email, comments, visited, subscribe) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['comments'], "text"),
GetSQLValueString($_POST['visited'], "text"),
GetSQLValueString($_POST['subscribe'], "text"));
mysql_select_db($database_connAdmin, $connAdmin);
$Result1 = mysql_query($insertSQL, $connAdmin) or die(mysql_error());
}
?><!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact form</title>
<link href="../examples/styles/contact.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Contact Us</h1>
<p>We welcome feedback from visitors to our site. Please use the following form to let us know what you think about it.</p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<fieldset>
<legend>Your details</legend>
<p>
<label for="name">Name: <?php
if (isset($missing) && in_array('name', $missing)) { ?>
<span class="warning">Please enter your name</span><?php } ?>
</label>
<input name="name" type="text" class="textInput" id="name"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['name']).'"';
} ?>
/>
</p>
<p>
<label for="email">Email:</label>
<input name="email" type="text" class="textInput" id="email"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['email']).'"';
} ?>
/>
</p>
</fieldset>
<fieldset>
<legend>Your views</legend>
<p>
<label for="comments">Comments: <?php
if (isset($missing) && in_array('comments', $missing)) { ?>
<span class="warning">Please enter your comments</span><?php } ?>
</label>
<textarea name="comments" id="comments" cols="45" rows="5"><?php if (isset($missing)) {
echo htmlentities($_POST['comments']);
} ?></textarea>
</p>
<p><strong>What aspects of London most interest you?</strong></p>
<div class="chkRad">
<p>
<input type="checkbox" name="interests[]" id="interests-classical" value="Classical concerts"
<?php
$OK = isset($_POST['interests']) ? true : false;
if ($OK && isset($missing) && in_array('Classical concerts', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-classical">Classical concerts</label>
</p>
<p>
<input name="interests[]" type="checkbox" id="interests-rock" value="Rock/pop"
<?php
if ($OK && isset($missing) && in_array('Rock/pop', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-rock">Rock/pop events</label>
</p>
<p>
<input name="interests[]" type="checkbox" id="interests-drama" value="Drama"
<?php
if ($OK && isset($missing) && in_array('Drama', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-drama">Drama</label>
</p>
</div>
<div class="chkRad">
<p>
<input name="interests[]" type="checkbox" id="interests-walks" value="Guided walks"
<?php
if ($OK && isset($missing) && in_array('Guided walks', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-walks">Guided walks</label>
</p>
<p>
<input name="interests[]" type="checkbox" id="interests-art" value="Art"
<?php
if ($OK && isset($missing) && in_array('Art', $_POST['interests'])) {
echo 'checked="checked"';
} ?>
/>
<label for="interests-art">Art</label>
</p>
</div>
<p class="clearIt">
<label for="visited">How often have you been to London? <?php
if (isset($missing) && in_array('visited', $missing)) { ?>
<span class="warning">Please select a value</span><?php } ?></label>
<select name="visited" id="visited">
<option value="0"
<?php
if (!$_POST || $_POST['visited'] == '0') {
echo 'selected="selected"';
} ?>
>-- Select one --</option>
<option value="Never"
<?php
if (isset($missing) && $_POST['visited'] == 'Never') {
echo 'selected="selected"';
} ?>
>Never been</option>
<option value="1-2 times"
<?php
if (isset($missing) && $_POST['visited'] == '1-2 times') {
echo 'selected="selected"';
} ?>
>Once or twice</option>
<option value="Not yearly"
<?php
if (isset($missing) && $_POST['visited'] == 'Not yearly') {
echo 'selected="selected"';
} ?>
>Less than once a year</option>
<option value="Yearly"
<?php
if (isset($missing) && $_POST['visited'] == 'Yearly') {
echo 'selected="selected"';
} ?>
>I go most years</option>
<option value="Live/work"
<?php
if (isset($missing) && $_POST['visited'] == 'Live/work') {
echo 'selected="selected"';
} ?>
>I live/work there</option>
</select>
</p>
<p>
<label for="views">What image do you have of London?</label>
<select name="views[]" size="6" multiple="multiple" id="views">
<option value="Vibrant/exciting"
<?php
$OK = isset($_POST['views']) ? true : false;
if ($OK && isset($missing) && in_array('Vibrant/exciting', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>A vibrant, exciting city</option>
<option value="Good food"
<?php
if ($OK && isset($missing) && in_array('Good food', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>A great place to eat</option>
<option value="Good transport"
<?php
if ($OK && isset($missing) && in_array('Good transport', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>Convenient transport</option>
<option value="Dull"
<?php
if ($OK && isset($missing) && in_array('Dull', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>Dull, dull, dull</option>
<option value="Bad food"
<?php
if ($OK && isset($missing) && in_array('Bad food', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>The food's rotten</option>
<option value="Transport nightmare"
<?php
if ($OK && isset($missing) && in_array('Transport nightmare', $_POST['views'])) {
echo 'selected="selected"';
} ?>
>A transport nightmare</option>
</select>
</p>
<p><strong>Would you like to receive regular details of events in London?</strong></p>
<div class="chkRad">
<p>
<input type="radio" name="subscribe" id="subscribe-yes" value="y"
<?php
if (isset($missing) && $_POST['subscribe'] == 'y') {
echo 'checked="checked"';
} ?>
/>
<label for="subscribe-yes">Yes</label>
<input name="subscribe" type="radio" id="subscribe-no" value="n"
<?php
if (!isset($missing) || isset($missing) && $_POST['subscribe'] == 'n') {
echo 'checked="checked"';
} ?>
/>
<label for="subscribe-no">No</label>
</p>
</div>
<p> </p>
<p class="clearIt">
<input type="submit" name="send" id="send" value="Send comments" />
</p>
</fieldset>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>