服务器端验证入门

好的,我正在尝试为我正在创建的网站创建一个php模型。 php脚本必须有一个验证脚本来检查表单,图像验证脚本以及向数据库提交信息。到目前为止,我已阅读了许多一半的书面教程,这些教程解释了一些事情,我要求个人一对一的帮助,要么就正确的方向指出如何实现这个目标。到目前为止,这是我的工作代码,它并不多,但我想它是一个开始。希望借助这个论坛来帮助我解决这些问题。非常感谢你。


[PHP]<? php


//确定是否点击了sumbit按钮。如果是这样,请开始验证表单数据。


if($ _POST [''submitB''] ==" Submit")

{

//确定是否输入了姓名


$ valid_form = true;


if($ _POST [''name ''] =="")

{

echo"输入你的名字&quot ;;

$ valid_form = false;

}


其他

{

$ name = $ _POST [''name''];

}


if($ _POST [''uname''] =="")

{

echo"输入用户名&quot ;;

$ valid_form = false;

}


else

{

$ username = $ _POST [''uname''];

}


if($ _POST [''pass''] =="")

{


echo"输入密码&quot ;;

$ valid_form = false;


}


elseif(strlen($ _ POST [''pass''])< 4)

{


echo"密码必须包含至少4个字符 ;

$ valid_form = false;

}


其他

{

$密码= $ _POST [''传递''];

}



//如果所有表单字段都已正确提交,开始处理


如果($ valid_form == true)

{


//表格处理代码去这里


}

}

?>

[/ PHP]


我有表格的各种输入,包括确认密码。希望有人可以提供帮助。

Ok, i am trying to create a php model for a website I am creating. The php script must have a validation script to check form, a image verification script and a submission of the information to a database. So far, i have read many half written tutorials that explained things but not in detail. I am asking either for personal one on one help with this or a point in the right direction as to how to accomplish this. So far this is the code i have for my work, its not much but i suppose its a start. Would love the help of this forum to get me past these issues. Thank you very much.

[PHP]<? php

//Determine if the sumbit button has been clicked. If so, begin validating form data.

if ($_POST[''submitB''] == "Submit")
{
//Determine if a Name was entered

$valid_form = true;

if ($_POST[''name''] == "")
{
echo "Enter your name";
$valid_form = false;
}

else
{
$name = $_POST[''name''];
}

if ($_POST[''uname''] == "")
{
echo "Enter a user name";
$valid_form = false;
}

else
{
$username = $_POST[''uname''];
}

if ($_POST[''pass''] == "")
{

echo "Enter a password";
$valid_form = false;

}

elseif (strlen($_POST[''pass'']) < 4)
{

echo "Password must contain at least 4 characters";
$valid_form = false;
}

else
{
$password = $_POST[''pass''];
}


//if all form fields were submitted properly, begin processing

if($valid_form == true)
{

//form processing code goes here

}
}
?>
[/PHP]

I have all kinds of inputs for the form, including a confirm password. Hopefully someone can help.



 1 条回答

php