提交表单时出错 [英] Getting an error when submitting form
本文介绍了提交表单时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单接受用户输入并将其发送到我的数据库。但是在点击提交时,我在文本框中收到错误请匹配请求的格式..
我不能纠正错误。请建议
表格:
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:
<!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>
PHP:
The 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";
}
}
}
}
?>
推荐答案
_session['username']))
\t{
\t\theader(\"Location:addnew.php\");
\t}
\t
\tfunction cleaninput(
_session['username'])) { header("Location:addnew.php"); } function cleaninput(
strings)
\t{
strings) {
strings=trim(
strings=trim(
这篇关于提交表单时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文