提交表单只是显示自己 [英] submitted form just shows itself
问题描述
我有一个用于注册新人的表单,当我点击
提交按钮时,表单就会显示出来。如果你将字段留空等,它应该显示一个
消息显示字段错误。
提交空表单应该显示红色的错误消息,然后显示
表格,但它只是表格形式。我检查了变量,使得他们没事,他们就没事了。我相信这是一个逻辑错误
我的if else ....我通过使用函数
和相同的结果模块化了一切。
>
如果有人看到逻辑错误,请告诉我。这里的代码:
<?php
函数showmessage(){
//检查以确保他们输入了有效的电子邮件地址。
if(eregi(" ^([[:alnum:]] | _ | \。| - )+ @([[:alnum:]] | \。 | - )+(\。)([az] {2,4})$",
$ HTTP_POST_VARS [''emailfield''])){
$ d = TRUE;
}其他{
$ d = FALSE;
$ message1 [] ="您输入的电子邮件地址是无效的。;
}
返回;
}
函数checkfields( )$
$ year = $ HTTP_POST_VARS [''yearfield''];
$ month = $ HTTP_POST_VARS [''monthfield''];
$ day = $ HTTP_POST_VARS [''dayfield''];
$ dobfield = $ year。$ month。$ day;
//检查姓氏。
if(eregi(" ^([[:alpha:]] | - |'')+ $",$ HTTP_POST_VARS [''usernamefield'']))
{
$ a = TRUE;
}否则{
$ a = FALSE;
$ message1 [] ="请输入正确的用户名。即; EricDerouen
只包含字母。;
}
//检查名字。
if(eregi(" ^([[:alpha:]] | - |'')+ $",
$ HTTP_POST_VARS [''firstnamefield''])){
$ b = TRUE;
}否则{
$ b = FALSE;
$ message1 [] = 请输入仅包含
字母的名字。;
}
//检查最后一个姓名。
if(eregi(" ^([[:alpha:]] | - |'')+ $",$ HTTP_POST_VARS [''lastnamefield'']))
{
$ c = TRUE;
}否则{
$ c = FALSE;
$ message1 [] ="请输入仅包含
字母的姓氏。" ;;
}
//检查以确保他们输入了有效的电子邮件地址。
if(eregi(" ^([[:alnum:]] | _ | \。| - )+ @([ [:alnum:]] | \。| - )+(\。)([az] {2,4})$",
$ HTTP_POST_VARS [''emailfield''] )){
$ d = TRUE;
}否则{
$ d = FALSE;
$ message1 [] ="您输入的电子邮件地址无效。" ;;
}
//检查密码字段。
if($ HTTP_POST_VARS [''passwordfield'']<> "{
$ e = TRUE;
}否则{
$ e = FALSE;
$ message1 [] ="请输入密码。" ;;
}
//检查验证密码。
if($ HTTP_POST_VARS [''confirmfield''] =
$ HTTP_POST_VARS [''$ passwordfield'']){
$ f = TRUE;
}其他{
$ f = FALSE;
$ message1 [] ="您输入的密码与密码不符
你确认了。" ;;
}
//检查城市。
if(eregi(" ^) ([[:alpha:]] | - |'')+ $",$ HTTP_POST_VARS [''cityfield''])){
$ g = TRUE;
} else {
$ g = FALSE;
$ message1 [] ="请输入仅包含字母的城市。;
}
//检查状态。
if(eregi(" ^([[:alpha:]] | - |' ')+ $",$ HTTP_POST_VARS [''statefield''])){
$ h = TRUE;
} e lse {
$ h = FALSE;
$ message1 [] ="请输入一个只包含字母的州。;
}
if(ereg("([0-9] {4}) - ([0-9] {2}) - ([0-9] {2 })",$ dobfield))
{
$ i = TRUE;
}否则{
$ i = FALSE;
$ message1 [] ="您输入的BIRTHDATE无效。" ;;
}
}
函数connectandinsert(){
$ hostname =" localhost";
$ database ="" ; //故意遗漏!
$ username ="" ;;
$ password ="" ;;
$ connection = mysql_connect($ hostname,$ username,$ password)或
die(mysql_error());
$ db = mysql_select_db($ database,$ connection)或die(不能
连接到数据库);
//将表格中的变量插入主表的时间。
$ query ="插入主要
(userneme,last,first,dob,参加,电子邮件,地址,城市,州,电话,
手机,出勤,密码)价值
(''$ userfield'',''$ lastnamefield'',''$ firstnamefiel d'',''$ dobfield'',''$ radiobutton2'',
''$ emailfield'',''$ addressfield'','$ cityfield'',''$ state field'',''$ phonefield'',''$ cellphone'' ,''$ radiobutton3'',''$ passwordfield'')" ;;
$ result = mysql_query($ query)
或死(无法执行查询。);
}
函数sendemails(){
//使用他提交的电子邮件向客户发送电子邮件。
$ message1 =" {$ firstnamefield},\ n \感谢您注册
Derouen Family Reunion.\
您已预先登记参加。委员会成员将与您联系。
。 \ n
您还将通过电子邮件地址收到最新的团聚。
提供。\ n
并且不要''忘记查看我们的家庭团聚网站,从时间到
time.\\\
\\\
Reunion Committee \\\
Databaseindays.com" ;;
if(mail( $ emailfield,Re:Your Derouen Family Reunion,$ message1))
{echo" +" ;;}
else {echo" - " ;}
//现在为什么不向我们自己发送所有信息。
$ message1 ="名字:$ firstnamefield \\\
Last名称:
$ lastnamefield\\\
Email:$ emailfield \ n电话:$ phonefield \ n
手机:$ cellphone \ nDOB:$ dobfield \ n $地址: $ addressfield \ n城市:
$ cityfield\\\
State:$ statefield \ nZip:$ zipfield \ n
出席:$ radiobutton2 \ n无人值守最后:$ radiobutton3 \ n" ;;
if(mail(" in ** @ databaseindays.com"," New Regi)德鲁恩的表格
家庭团聚,$ message1))
{echo" +" ;;}
else {echo" - " ;;}
}
// ************************** ************************ ************************** ******
if(!isset($ _ POST [''submitbut'']))
{
include(" ; showreg_form.html");
退出;
}
checkfields();
if($ a AND $ b AND $ c AND $ d AND $ e AND $ f AND $ g AND $ h AND $ i)
{
connectandinsert();
sendemails();
echo一切顺利。插入并通过电子邮件发送你的屁股;
}
其他
{
showmessage();
包括(showreg_form.html);
}}
?>
I have a form i will use to register new people and when I click the
submit button, the form just shows itself. It is supposed to show a
message showing field errors if you leave fields blank etc. so
submitting the empty form should show error message in red , then show
form, but all it does is show form. I checked the variable to make
shore they ere ok and they are fine. i believe it is a logical error
with my if else.... I eved modularized everything by using functions
and the same results.
if any one sees the logical error, let me know. Here the code:
<?php
function showmessage() {
// Check to make sure they entered a valid email address.
if (eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$",
$HTTP_POST_VARS[''emailfield''])) {
$d = TRUE;
} else {
$d = FALSE;
$message1[] = "The email address you entered is not valid.";
}
return;
}
function checkfields(){
$year = $HTTP_POST_VARS[''yearfield''];
$month = $HTTP_POST_VARS[''monthfield''];
$day = $HTTP_POST_VARS[''dayfield''];
$dobfield = $year.$month.$day;
// Check the last name.
if (eregi ("^([[:alpha:]]|-|'')+$", $HTTP_POST_VARS[''usernamefield'']))
{
$a = TRUE;
} else {
$a = FALSE;
$message1[] = "Please enter a correct username. I.e; EricDerouen
that consists only of letters.";
}
// Check the first name.
if (eregi ("^([[:alpha:]]|-|'')+$",
$HTTP_POST_VARS[''firstnamefield''])) {
$b = TRUE;
} else {
$b = FALSE;
$message1[] = "Please enter a First Name that consists only of
letters.";
}
// Check the last name.
if (eregi ("^([[:alpha:]]|-|'')+$", $HTTP_POST_VARS[''lastnamefield'']))
{
$c = TRUE;
} else {
$c = FALSE;
$message1[] = "Please enter a Last Name that consists only of
letters.";
}
// Check to make sure they entered a valid email address.
if (eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$",
$HTTP_POST_VARS[''emailfield''])) {
$d = TRUE;
} else {
$d = FALSE;
$message1[] = "The email address you entered is not valid.";
}
// Check the password field.
if ($HTTP_POST_VARS[''passwordfield''] <> "") {
$e = TRUE;
} else {
$e = FALSE;
$message1[] = "Please enter a password.";
}
// Check validate password.
if ($HTTP_POST_VARS[''confirmfield''] =
$HTTP_POST_VARS[''$passwordfield'']) {
$f = TRUE;
} else {
$f = FALSE;
$message1[] = "The password you entered do not match the password
you confirmed.";
}
// Check the City.
if (eregi ("^([[:alpha:]]|-|'')+$", $HTTP_POST_VARS[''cityfield''])) {
$g = TRUE;
} else {
$g = FALSE;
$message1[] = "Please enter a City that consists only of letters.";
}
// Check the state.
if (eregi ("^([[:alpha:]]|-|'')+$", $HTTP_POST_VARS[''statefield''])) {
$h = TRUE;
} else {
$h = FALSE;
$message1[] = "Please enter a State that consists only of letters.";
}
if (ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$dobfield))
{
$i = TRUE;
} else {
$i = FALSE;
$message1[] = "The BIRTHDATE you entered is invalid.";
}
}
function connectandinsert(){
$hostname = "localhost";
$database = ""; //intentionally left out!
$username = "";
$password = "";
$connection = mysql_connect($hostname, $username, $password) or
die(mysql_error());
$db = mysql_select_db($database, $connection) or die ("could not
connect to database");
//Time to insert variables from form into main table.
$query = "insert into main
(userneme,last,first,dob,attending,email,address,c ity,state,phone,
cellphone,attendedlast,password) values
(''$usernamefield'',''$lastnamefield'',''$firstnamefiel d'',''$dobfield'',''$radiobutton2'',
''$emailfield'',''$addressfield'',''$cityfield'',''$state field'',''$phonefield'',''$cellphone'',''$radiobutton3'', ''$passwordfield'')";
$result = mysql_query($query)
or die ("could not execute query.");
}
function sendemails(){
//send email to customer using email he submitted.
$message1 = "{$firstnamefield},\n \nThank you for registering For the
Derouen Family Reunion.\n
You have been pre-registered to attend. A committee member will be
contacting you. \n
You will be also receive the latest Reunion via the E-Mail address
provided.\n
And don''t forget to check our family reunion web-site from time to
time.\n \nReunion Committee\n Databaseindays.com";
if (mail($emailfield,"Re: Your Derouen Family Reunion",$message1))
{echo "+";}
else {echo "-";}
//now why not send one to ourself with all the information.
$message1 = "First name: $firstnamefield\nLast Name:
$lastnamefield\nEmail: $emailfield\nPhone: $phonefield\n
cellphone: $cellphone\nDOB: $dobfield\n$Address: $addressfield\n City:
$cityfield\nState: $statefield\nZip: $zipfield\n
Attending: $radiobutton2\nAttended Last: $radiobutton3\n";
if (mail("in**@databaseindays.com","New Registration Form for Derouen
Family Reunion",$message1))
{echo "+";}
else {echo " -";}
}
//************************************************** ********************************
if (!isset($_POST[''submitbut'']))
{
include("showreg_form.html");
exit;
}
checkfields();
if ($a AND $b AND $c AND $d AND $e AND $f AND $g AND $h AND $i)
{
connectandinsert();
sendemails();
echo "all went well. inserted and emailed your ass";
}
else
{
showmessage();
include("showreg_form.html");
}}
?>
推荐答案
",
",
HTTP_POST_VARS [''emailfield''])){
HTTP_POST_VARS[''emailfield''])) {
>
d = TRUE;
}其他{
d = TRUE;
} else {
这篇关于提交表单只是显示自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!