form handling problems

My form wont process the data I input - nothing happens.

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1262 Views - Last Post: 02 April 2008 - 10:02 AM Rate Topic: -----

#1 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

form handling problems

Post icon  Posted 01 April 2008 - 01:24 PM

2 files: register.php contains the form that will collect personal details from a new user who wants to register. action_register.php handles the data and stores it in a mysql database.

When I click on submit nothing happens...I've been pulling my hair out because I'm sure it's something really minor! Can anyone help me please and let me know what I've done wrong??

File 1: register.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Register New User</title>
	</head>

<body>

<form action="input" action="action_register.php" method="post">
	<h3 align="center">Personal Details</h3>
	<table border cellspacing="5" cellpadding="5" align="center">
		<tr>
			<td>Title:</td>
			<td><select name="title">
				<option value="mr">Mr</option>
				<option value="miss">Miss</option>
				<option value="mrs">Mrs</option>
				<option value="ms">Ms</option>
				<option value="dr">Dr</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Forename(s):</td>
			<td><input type="text" name="forename" size="20" maxlength="50"></td>
		<tr>
			<td>Surname:</td>
			<td><input type="text" name="surname" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Date of Birth:</td>
			<td><input type="text" name="dob" size="10" maxlength="20"></td>
		</tr>
		<tr>
			<td>Address(line 1):</td>
			<td><input type="text" name="address1" size="20" maxlength="50"></td>
		</tr>
			<td>Address(line 2):</td>
			<td><input type="text" name="address2" size="20" maxlength="50"></td>
		</tr>
			<td>Address(line 3):</td>
			<td><input type="text" name="address3" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Town/City:</td>
			<td><input type="text" name="town_city" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>County/State</td>
			<td><input type="text" name="county_state" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Postal Code:</td>
			<td><input type="text" name="postal_code" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Country:</td>
			<td><input type="text" name="country" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Trading Experience:</td>
			<td><select name="trading_experience">
				<option value="beginner">Beginner</option>
				<option value="intermediate">Intermediate</option>
				<option value="advanced">Advanced</option>
		</tr>
	</table>
	
	<h3 align="center">Login Details</h3>
	<table border cellspacing="5" cellpadding="5" align="center">
		<tr>
			<td>Display Name:</td>
			<td><input type="text" name="display_name" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Email Address:</td>
			<td><input type="text" name="email" size="20" maxlength="80"></td>
		</tr>
		<tr>
			<td>Password:</td>
			<td><input type="password" name="password" size="20" maxlength="50"></td>
		</tr>
		<tr>
			<td>Confirm Password:</td>
			<td><input type="password" name="password2" size="20" maxlength="50"></td>
		</tr>
	</table>
	<center><input type="submit" name="submit" value="Submit" />
	</center>
	
</form>


</body>
</html>



File 2: action_register.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Actioning New Registered Users</title>
	</head>

<body>
<?php
	// Checking to see if the 'submit' button has been pressed
	if (isset($_POST['submitted'])){
	
	$errors = array(); // Initialise error array.
	
	// Checking if 'title' has been selected.
	if (empty($_POST['title'])){
		$errors[] = 'You forgot to select your title.'
	}
	else{
		$t = trim($_POST['title']);
	}
	
	// Checking for first name.
	if (empty($_POST['forename'])){
		$errors[] = 'You forgot to enter your first name.'
	}
	else{
		$fn = trim($_POST['forename']);
	}
	
	// Checking for last name.
	if (empty($_POST['surname'])){
		$errors[] = 'You forgot to enter your Surname.'
	}
	else{
		$sn = trim($_POST['surname']);
	}
	
	// Checking for D.O.B
	if (empty($_POST['dob'])){
		$errors[] = 'You forgot to enter your Date of Birth or, use the format YYYY-MM-DD.'
	}
	else{
		$dob = ($_POST['dob']);
	}
	
	// Checking for 1st line of address only.
	if (empty($_POST['address1'])){
		$errors[] = 'You forgot to enter the 1st line of your address.'
	}
	else{
		$ad1 = trim($_POST['address1']);
	}
	
	// Checking if a 2nd line has been inputted for the address.
	if (isset($_POST['address2'])){
		$ad2 = trim($_POST['address2']);
	}
	
	// Checking if a 3rd line has been inputted for the address.
	if (isset($_POST['address3'])){
		$ad3 = trim($_POST['address3']);
	}
	
	// Checking for town/city.
	if (empty($_POST['town_city'])){
		$errors[] = 'You forgot to enter your Town/City.'
	}
	else{
		$tc = trim($_POST['town_city']);
	}
	
	//Checking for County/State.
	if (empty($_POST['county_state'])){
		$errors[] = 'You forgot to enter your County/State.'
	}
	else{
		$cs = trim($_POST['county_state']);
	}
	
	// Checking for Post Code.
	if (empty($_POST['postal_code'])){
		$errors[] = 'You forgot to enter your first name.'
	}
	else{
		$pc = trim($_POST['postal_code']);
	}
	
	// Checking for Country.
	if (empty($_POST['country'])){
		$errors[] = 'You forgot to enter your Country.'
	}
	else{
		$ctry = trim($_POST['country']);
	}
	
	// Checking for trading experience
	if (empty($_POST['trading_experience'])){
		$errors[] = 'You forgot to select your Trading Experience skill level.'
	}
	else{
		$tr = trim($_POST['trading_experience']);
	}
	
	// Checking for a Display Name
	if (empty($_POST['display_name'])){
		$errors[] = 'You forgot to enter your Display Name.'
	}
	else{
		$dname = trim($_POST['display_name']);
	
	
	// Checking if an email has been entered..........
	if (empty($_POST['email'])){
		$errors[] = 'You forgot to enter you email address.'
	}
	else{
		$em1 = trim($_POST['email']);
		
	// ....Also checking if email already exists
	require_once('databaseconnect2.php');

	$query = "SELECT email FROM users
			  WHERE email = '$em1'";

	$result = mysql_query($query);
		if (mysql_num_rows($result) == 0){
			$em = trim($_POST['email']);
		}
		else{
			$errors[] = 'The Email Address you provided is already registered. Please try another.'
		}
	
		
	//Check password and match against the confirmed password
	if (!empty($_POST['password'])){
		if ($_POST['password'] != $_POST['password2']){
			$errors[] = 'Your password did not match the confirmed password.';
		}
		else{
			$p = trim($_POST['password']);
	}
	}else{
		$errors[] = 'You forgot to enter your password.';
	}
	
	// If there are no errors in the $errors array...then everything is OK.
	if (empty($errors)){
		require_once('databaseconnect2.php'); // Connect to database
		
	// Make the query
	$query = "INSERT into users (title, forename, surname, dob, address1, address2, address3, town_city, county_state, postal_code, country, trading_experience, display_name, email, password)
			VALUES ('$t', '$fn', '$sn', '$dob', '$ad1', '$ad2', '$ad3', '$tc', '$cs', '$pc', '$ctry', '$tr', '$dname', '$em', SHA('$p'))";
			 
	$result = @mysql_query($query);  // Run the query
	
	// Print a message.
	echo '<h1>Thank you!</h1>
	<p>You are now registered!</p>';
	
	// quit the script (to not show the form).
	exit();
	}
	else{ // If it did not run OK.
		echo '<h1>System Error</h1>
			<p>You could not be registered due to a system error.</p>';
			echo '<p>' . mysql_error() .'</p>'; //error message
			exit();
	}
	
		
?>

</body>
</html>
	<?php
		mysql_close(); // Close the database connection.
	?>
 


Is This A Good Question/Topic? 0
  • +

Replies To: form handling problems

#2 spearfish  Icon User is offline

  • Monkey in Training
  • member icon

Reputation: 10
  • View blog
  • Posts: 746
  • Joined: 10-March 08

Re: form handling problems

Posted 01 April 2008 - 01:33 PM

Are you getting an error? What is it?

In effect, please be more specific in telling what is wrong.
Was This Post Helpful? 0
  • +
  • -

#3 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 01 April 2008 - 02:43 PM

Oops sorry! There is no error message....I just get a message on IE that it could not open the page. I have been reading some tutorials about the hidden input types that save the state of the form data???? Or am I talkin gibberish??
Was This Post Helpful? 0
  • +
  • -

#4 spearfish  Icon User is offline

  • Monkey in Training
  • member icon

Reputation: 10
  • View blog
  • Posts: 746
  • Joined: 10-March 08

Re: form handling problems

Posted 01 April 2008 - 02:46 PM

Quote

<form action="input" action="action_register.php" method="post">


Reexamine that line.
Was This Post Helpful? 0
  • +
  • -

#5 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 05:41 AM

Excellent!! Thank you...you resolved that problem for me! But I keep getting a new error message when I submit the form data:

Parse error: parse error, unexpected '}' in h:\Project\htdocs\action_register.php on line 18

 // Checking if 'title' has been selected.
	if (empty($_POST['title'])){
		$errors[] = 'You forgot to select your title.'
	}  // THIS IS LINE 18
	else{
		$t = trim($_POST['title']);
	}


Was This Post Helpful? 0
  • +
  • -

#6 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 06:00 AM

Stupid me!....I forgot to put the ';' after each error message!
Was This Post Helpful? 0
  • +
  • -

#7 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 07:28 AM

Hello again! Im sorry if this is getting annoying for anyone but everytime I resolve a problem..a new 1 arrives!

My action_register.php file now looks like this after editing the section which makes and executes the sql query, and adding some more coding to report the errors and the form. Here is the extract:

 // Make the query
	$query = "INSERT into users (title, forename, surname, dob, address1, address2, address3, town_city, county_state, postal_code, country, trading_experience, display_name, email, password, balance)
			VALUES ('$t', '$fn', '$sn', '$dob', '$ad1', '$ad2', '$ad3', '$tc', '$cs', '$pc', '$ctry', '$tr', '$dname', '$em', SHA('$p'), '100000.00')";
			 
	$result = @mysql_query($query);  // Run the query
	
	if ($result){ // If it ran OK...
		// ...Print the following message:
		echo '<h1>Thank you!</h1>
		<p>You are now registered!</p>';
	
		// quit the script (to not show the form).
		exit();
	}
	else{ // If it did not run OK.
		echo '<h1>System Error</h1>
			<p>You could not be registered due to a system error.</p>';
		echo '<p>' . mysql_error() .'</p>'; //error message
		exit();
	}
	mysql_close(); // Close the database connection.
	
	}
	else{ // report the errors
		echo '<h1>Error!</h1> <p>The following error(s) occurred:<br />';
		
		foreach ($errors as $msg){ // Print each error.
			echo " - $msg<br />\n";
		}
	echo '</p><p>Please try again.</p><p><br/></p>';
	} // End of if (empty($errors)) IF.
	} // End of the main Submit conditional.
	
	<h2>Register</h2><form action="action_register.php" method="post"> // ### THIS IS LINE 184 ###
	
	<p>First Name: <input type="text" name="forename" size="20" maxlength="50" value="
	<?php if (isset($_POST['forename'])) echo $_POST['forename']; ?>"
	 /></p>
	
	<p>Last Name: <input type="text" name="surname" size="20" maxlength="50"value="
	<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>"
	 /></p>
	
	<p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="
	<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"
	 /></p>
	
	<p>Password: 
	<input type="password" name="password" size="20" maxlength="40" /></p>
	
	<p>Confirm Password: 
	<input type="password" name="password2" size="20" maxlength="40" /></p>
	
	<p><input type="submit" name="submit" value="Register" /></p>
	<input type="hidden" name="submit" value="TRUE" /></form>
	
	
		
?>

</body>
</html> 


I keep getting an error message saying:
Parse error: parse error, unexpected '<' in h:\Project\htdocs\action_register.php on line 184

I have made a comment next to the line where the error occurs. Could anyone please help me??

Thank you
Was This Post Helpful? 0
  • +
  • -

#8 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: form handling problems

Posted 02 April 2008 - 07:39 AM

Are you forgetting to close the php block immediately before that line?
Was This Post Helpful? 0
  • +
  • -

#9 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 07:49 AM

I'm really sorry I dont understand. Do you mean to put a '?>' at the beginning of that line in question? If I do that I get a new error msg saying:
Parse error: parse error, unexpected $end in h:\Project\htdocs\action_register.php on line 212
and this is right at the end of the script after </html>
Was This Post Helpful? 0
  • +
  • -

#10 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: form handling problems

Posted 02 April 2008 - 08:13 AM

That is what I mean, yes. I think you also have an unnecessary closing php tag just before your closing body tag, which causes the new error.
Was This Post Helpful? 0
  • +
  • -

#11 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 08:21 AM

Thanks for the help! OK so I've added the '?>' where you asked me, I removed the unnecessary '?>' tag just before my closing body tag. and now I get the error message:

Parse error: parse error, unexpected $end in h:\Project\htdocs\action_register.php on line 207

This is the same line as before (the closing html tag)
Was This Post Helpful? 0
  • +
  • -

#12 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: form handling problems

Posted 02 April 2008 - 08:39 AM

Well, I'm not sure what's wrong now, but that error message normally means there are some braces left open or unbalanced somewhere. The only suggestions I have are to look back at the page carefully for unbalanced braces and post the entire page back here for for us to try and spot it for you.
Was This Post Helpful? 0
  • +
  • -

#13 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 08:47 AM

View Postthehat, on 2 Apr, 2008 - 08:39 AM, said:

Well, I'm not sure what's wrong now, but that error message normally means there are some braces left open or unbalanced somewhere. The only suggestions I have are to look back at the page carefully for unbalanced braces and post the entire page back here for for us to try and spot it for you.



Thank you for helping out. I will be checking the files from top to bottom to see where I've gone wrong. If you would like to see the scripts in full I've sent them as an attachment. Its just 2 files: register.html (the actual form) and action_register.php (form processor).

Thank you

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#14 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: form handling problems

Posted 02 April 2008 - 09:00 AM

Ok first, and unrelated, you should close your select tag in register.html:

<select name="trading_experience">
	<option value="beginner">Beginner</option>
	<option value="intermediate">Intermediate</option>
	<option value="advanced">Advanced</option>
</select>



Now for the php. Take a look at lines 110 and 118. There could be a } missing after those two else statements.

Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#15 singhs2  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 33
  • Joined: 22-December 07

Re: form handling problems

Posted 02 April 2008 - 09:43 AM

Oh My God!!! Thank you soooo much for helping....I've been pulling my hair out over this script for a few days...and now it works perfect! The script is being used as part of my final year project at university for a Fantsy Stock Market Trader Game.

Much Appreciated for your help. I'm sure it won't be long until I find my next problem elsewhere....I'm hoping I won't though!

Thank you :-)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2