Simple contact us Page

Dear All,

I am a new bee and trying to make a simple contact us page but its showing some errors, please suggest me how I can fix this error:

below is the html:
<?php
session_start();
?>
<!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>
</head>

<body>

<h1> Contact Form</h1>

<form action=“form_process.php” method=“post”>

&lt;table cellspacing='10' cellpadding='10' width='750'&gt;
    &lt;tr&gt;
    &lt;td&gt;&lt;b&gt;Name:&lt;/b&gt; &lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='name' value='&lt;?php if {isset($_SESSION['name'])} {echo $_SESSION['name'];} ?&gt;' &gt; &lt;/td&gt;
    &lt;td&gt;&lt;?php if {isset($_SESSION['error_name'])} {echo $_SESSION['error_name'];}?&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
    &lt;td&gt;&lt;b&gt;Surname:&lt;/b&gt; &lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='surname' value='&lt;?php if {isset($_SESSION['surname'])} {echo $_SESSION['surname'];} ?&gt;' &gt; &lt;/td&gt;
    &lt;td&gt;&lt;?php if {isset($_SESSION['error_surname'])} {echo $_SESSION['error_surname'];}?&gt; &lt;/td&gt;
    &lt;/tr&gt;
            
    &lt;tr&gt;
    &lt;td&gt;&lt;b&gt;Phone Number:&lt;/b&gt; &lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='phone' value='&lt;?php if {isset($_SESSION['phone'])} {echo $_SESSION['phone'];} ?&gt;' &gt; &lt;/td&gt;
    &lt;td&gt;&lt;?php if {isset($_SESSION['error_phone'])} {echo $_SESSION['error_phone'];}?&gt; &lt;/td&gt;
    &lt;/tr&gt;
            
    &lt;tr&gt;
    &lt;td&gt;&lt;b&gt;Email Address:&lt;/b&gt; &lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='email' value='&lt;?php if {isset($_SESSION['email'])} {echo $_SESSION['email'];}?&gt;' &gt; &lt;/td&gt;
    &lt;td&gt;&lt;?php if {isset($_SESSION['error_email'])} {echo $_SESSION['error_email'];}?&gt; &lt;/td&gt;
    &lt;/tr&gt;
    
    &lt;tr&gt;
    &lt;td&gt;&lt;b&gt;Website:&lt;/b&gt; &lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='website' value='http://' &gt; &lt;/td&gt;
    &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    
    &lt;tr&gt;
    &lt;td valign='top'&gt;&lt;b&gt;Comments:&lt;/b&gt; &lt;/td&gt;
    &lt;td&gt;&lt;textarea cols='26' rows='6' name='comments' &gt;&lt;?php if {isset($_SESSION['comments'])} {echo $_SESSION['comments'];}?&gt;&lt;/textarea&gt;&lt;/td&gt;
    &lt;td&gt;&lt;?php if {isset($_SESSION['error_comments'])} {echo $_SESSION['error_comments'];}?&gt; &lt;/td&gt;
    &lt;/tr&gt;
            
    &lt;tr&gt;
    &lt;td&gt; &lt;/td&gt;
    &lt;td colspan='2'&gt;
    &lt;input type='submit' name='reset' value='Reset Form' &gt;
    &lt;input type='submit' name='submit' value='Submit Form' &gt;
    &lt;/td&gt;
    &lt;/tr&gt;
         
&lt;/table&gt;

</form>

</body>
</html>

below is the php script(form_process.php):

<?php

session_start();
if($_POST['submit']) {

$num = 0; 

	if(strlen($_POST['name']) &gt; 0) {
	$num = $num;
	$_SESSION['name'] = $_POST['name'];
	unset($_SESSION['error_name']);
			
	} else {
	$num = $num + 1;
	$_SESSION['error_name'] = "You have not filled out a Name";

	}
	
	if(strlen($_POST['surname']) &gt; 0) {
	$num = $num;
	$_SESSION['surname'] = $_POST['surname'];
	unset($_SESSION['error_surname']);
			
	} else {
	$num = $num + 1;
	$_SESSION['error_surname'] = "You have not filled out a Surname";

	}
	
	if(strlen($_POST['phone']) &gt; 0) {
	$num = $num;
	$_SESSION['phone'] = $_POST['phone'];
	unset($_SESSION['error_phone']);
			
	} else {
	$num = $num + 1;
	$_SESSION['error_phone'] = "You have not filled out a ";

	}
	
	if(strlen($_POST['email']) &gt; 0) {
	$num = $num;
	$_SESSION['email'] = $_POST['email'];
	unset($_SESSION['error_email']);
			
	} else {
	$num = $num + 1;
	$_SESSION['error_email'] = "You have not filled out a Email ";

	}
	
	if(strlen($_POST['comments']) &gt; 0) {
	$num = $num;
	$_SESSION['comments'] = $_POST['comments'];
	unset($_SESSION['error_comments']);
			
	} else {
	$num = $num + 1;
	$_SESSION['error_comments'] = "You have not filled out a Comment";

	}
	
	if($num == 0){
	
	// process form
	echo "success";
	
	else {
	
	header("Location: index.php")
	}
	
	}
} else {

header("Location: index.php");

}

?>

Are you going to tell us what the errors are, or are they a secret? :slight_smile:

Also, when you’re in the “Advanced” editor option, wrap your code in code tags (the # symbol in the editor toolbar). This will make your code much easier to read for most people - and it’ll get rid of those pesky gremlins about to munch up bits of your code.

Well…

  1. You have emoticon’s that are eating your Carrot’s… (it could turn into a zombie frenzy)

  2. I am curious why you are trying to create SESSION data out of your POST data, if you are intent on using SESSION, what are you doing with the SESSION data later on, why not send your POST data to a database or via email (SMTP obviously would be required),

  3. I dont think you have a blank page, I think your script is working perfectly… what is happening is because you are setting your data to SESSION ( think of it like a internet cookie), try adding a echo or print at the end of your script something like this

Print_r ($_SESSION);

and see if you get a blank page

Ok, i took your code and run it on my computer.

I got errors like this


Parse error: syntax error, unexpected '{', expecting '(' in F:\\www\	este\\contact.php on line 20

You did not declare the if() in the correct way

So you should write it

<?php if(isset($_SESSION['name'])) {echo $_SESSION['name'];} ?>'

insteaf of

<?php if {isset($_SESSION['name'])} {echo $_SESSION['name'];} ?>'

Just replace the {} with () and it will be fine

Correct the problem(s) and tell us if you get more errors. And don’t forget to copy&paste your code to us.