# Contact form issue

**URL:** <https://forum.kirupa.com/t/contact-form-issue/241446>\
**Category:** programming\
**Created:** [October 14, 2007, 6:25am UTC](https://forum.kirupa.com/t/contact-form-issue/241446 "2007-10-14T06:25:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anothermethod](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@anothermethod](https://forum.kirupa.com/u/anothermethod)\
**Post date:** [October 14, 2007, 6:25am UTC](https://forum.kirupa.com/t/contact-form-issue/241446/1 "2007-10-14T06:25:27Z")

</div>

Hello - I’ve been working on this contact form that writes the users info to db. Everything works great but I’m having trouble with displaying a confirmation message after the user submits their information. Please help if you can!!

Thanks,

AM,

Here is the code I’m using

* * *

\<?php  
include ‘includes/config.php’;  
include ‘includes/opendb.php’;

mysql\_select\_db(‘newsletter2’) or die(‘Cannot select database’);

$query = 'CREATE TABLE guestbook ( '.  
'id INT(10) UNSIGNED NOT NULL AUTO\_INCREMENT, '.  
'name VARCHAR(30) NOT NULL, '.  
'email VARCHAR(50) NOT NULL, '.  
'entry\_date DATE NOT NULL, '.  
‘PRIMARY KEY(id))’;

$result = mysql\_query($query);

// check if the form is submitted  
if(isset($\_POST[‘btnSign’]))  
{  
// get the input from $\_POST variable  
// trim all input to remove extra spaces  
$name = trim($\_POST[‘Name’]);  
$email = trim($\_POST[‘Email’]);

```
// escape the message ( if it's not already escaped )
if(!get_magic_quotes_gpc())
{
    $name = addslashes($name);
}

// if the visitor do not enter the url
// set $url to an empty string
if ($url == 'http://')
{
    $url = '';
}

// prepare the query string
$query = "INSERT INTO guestbook (name, email, entry_date) " .
         "VALUES ('$name', '$email', current_date)";

// execute the query to insert the input to database
// if query fail the script will terminate         
mysql_query($query) or die('Error, query failed. ' . mysql_error());

// redirect to current page so if we click the refresh button 
// the form won't be resubmitted ( as that would make duplicate entries )
header('Location: ' . $_SERVER['REQUEST_URI']);

// force to quite the script. if we don't call exit the script may
// continue before the page is redirected

exit;

```

}  
?\>  
\<html\>  
\<head\>  
\<title\>Guestbook\</title\>  
\<script language=“JavaScript” src=“gen\_validatorv2.js” type=“text/javascript”\>\</script\>  
\<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”\>  
\<link rel=“stylesheet” type=“text/css” href=“styles/styles.css”\>  
\</head\>  
\<body\>  
\<form method=“post” name=“guestform”\>  
\<table width=“550” border=“0” cellpadding=“2” cellspacing=“1”\>  
\<tr\>  
\<td width=“100”\>Name \*\</td\> \<td\>  
\<input name=“Name” type=“text” id=“txtName” size=“30” maxlength=“30”\>\</td\>  
\</tr\>  
\<tr\>  
\<td width=“100”\>Email\</td\>  
\<td\>  
\<input name=“Email” type=“text” id=“txtEmail” size=“30” maxlength=“50”\>\</td\>  
\</tr\>  
\<tr\>  
\<td width=“100”\>&nbsp;\</td\>  
\<td\>  
\<input name=“btnSign” type=“submit” id=“btnSign” value=“Sign Guestbook” onClick=“return checkForm();”\>\</td\>  
\</tr\>  
\</table\>  
\</form\>  
\<script language=“JavaScript” type=“text/javascript”\>  
//You should create the validator only after the definition of the HTML form  
var frmvalidator = new Validator(“guestform”);  
frmvalidator.addValidation(“Name”,“req”,“Please enter your Name”);  
frmvalidator.addValidation(“Name”,“maxlen=20”,  
“Max length for Name is 20”);  
frmvalidator.addValidation(“Name”,“alpha”);

frmvalidator.addValidation(“Email”,“maxlen=50”);  
frmvalidator.addValidation(“Email”,“req”);  
frmvalidator.addValidation(“Email”,“email”);

\</script\>  
\<br\>  
\<br\>

\</body\>  
\</html\>

* * *
