Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form to accept the user input and send it to my database. But on clicking submit i am getting error in the text-box as "PLEASE MATCH THE REQUESTED FORMAT"..

I am not bale to rectify the error. Kindly advise
The Form:

HTML
<!DOCTYPE HTML>
<html>
<head>
<title>Add New Contacts</title>
<link rel="stylesheet" href="addnew.css" type="text/css"/>
</head>

<body>
<header>
	<nav class="navigation">
	<a href="#">Edit Contacts</a>
	<a href="#">Delete Contact</a>
	<a href="#">Logout</a>
	</nav>
</header>
<div id="contact-form" class="mycontact">

<ul id="errors" class="">
<li id="info">Please recheck your form and Submit again: </li>
</ul>

<p id="success">Details Saved Successfully!!</p>

<form action="validate_addnew.php" method="POST">

<label for="Fname">First Name <span class="required">*</span>:</label>
<input type="text" id="First_Name" name="firstname" value="" pattern="[A-Za-z0-9]{50}" required="required" autofocus="autofocus"/>

<label for="Mname">Middle Name :</label>
<input type="text" id="Middle_Name" name="middlename" pattern="[A-Za-z]{30}" value=""/>

<label for="Lname">Last Name <span class="required">*</span>:</label>
<input type="text" id="Last_Name" name="lastname" value="" pattern="[A-Za-z]{40}" required="required"/>

<label for="email">Email <span class="required">*</span>:</label>
<input type="email" id="email" name="email" value="" placeholder="username@example.com" required="required"/>

<label for="Phone1">Phone 1:<span class="required">*</span>:</label>
<input type="text" id="contactHome" name="phone1" pattern="[0-9]{10}" value="" required="required"/>

<label for="Phone2">Phone 2:</label>
<input type="text" id="contactOffice" name="phone2" pattern="[0-9]{10}" value=""/>

<label for="Address1">Address<span class="required">*</span>:</label>
<textarea id="address1" name="address" required="required" data-maxlength="20"></textarea>

<label for="city">City<span class="required">*</span>:</label>
<input type="city" id="city" name="city" value="" required="required"/>

<label for="state">State <span class="required">*</span>:</label>
<input type="state" id="state" name="state" value="" required="required"/>

<label for="country">Country <span class="required">*</span>:</label>
<input type="country" id="country" name="country" value="" required="required"/>

<label for="zip">Zip <span class="required">*</span>:</label>
<input type="zip" id="zip" name="zip" value="" required="required"/>

<input type="Submit" value="Submit" id="submit-button"/>

<p id="required-desc"><span class="required">*</span> indicates a required field</p>
</form>
</div>
</body>
</html>



The PHP:

PHP
<?php
	
	session_start();
	
	require('connection.php');
	
	if(isset($_session['username']))
	{
		header("Location:addnew.php");
	}
	
	function cleaninput($strings)
	{
		$strings=trim($strings);
		
		if(get_magic_quotes_gpc())
		{
			$strings=stripslashes($strings);
		}
		
		return mysql_real_escape_string($strings);
	}
	
	if(isset($_POST['submit']))
	{
		$username=cleaninput($_POST('username'));
		$firstname=cleaninput($_POST('firstname'));
		$middlename=cleaninput($_POST('middlename'));
		$lastname=cleaninput($_POST('lastname'));
		$email=cleaninput($_POST('email'));
		$password=cleaninput($_POST('password'));
		$cnfpassword=cleaninput($_POST('cnfpassword'));
		
		if($username=="" || $firstname=="" || $lastname=="" || $email=="" || $password=="" || $cnfpassword=="")
		{
			echo "Please fill in all the required information!";
		}
		else
		{
			if($password!=$cnfpassword)
			{
				echo "Passwords do not match! Please try again";
			}
			else
			{
				$sqlquery =mysqli_query($connect, "SELECT * FROM usertable WHERE username='username'");
				
				$return=mysqli_num_rows($sqlquery);
				
				if($return==1)
				{
					echo "Sorry!! This username is already taken! Please give another username";
				}
				else
				{
					$adduser=mysqli_query($connect,"INSERT INTO usertable(username, firstname,middlename,lastname,email,password) VALUES('$username','$firstname','$middlename','$lastname','email','$password')");
					echo "User Created successfully!<a href='login.php'>Click here </a>to login";
				}
			}
		}
	}

?>
Posted
Updated 17-Mar-14 23:10pm
v2

1 solution

I noticed that the names of some of the html input tags are not the same as their corresponding $_POST names. They are case-sensitive.

+++++++++++++++++++++++++++++++++++

After my initial solution, I noticed you have just changed all the html input tag names to lower case in your question. I also spotted one more typo, shouldn't 'email' be '$email' in the sqli_query?
 
Share this answer
 
v6
Comments
Peter Leow 18-Mar-14 5:17am    
I noticed you have just changed the html input tag names to lower case in your question. I also spotted one more typo, shouldn't 'email' be '$email' in the sqli_query?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900