Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP表单验证后为空_Php_Mysql_Sql_Forms_Validation - Fatal编程技术网

PHP表单验证后为空

PHP表单验证后为空,php,mysql,sql,forms,validation,Php,Mysql,Sql,Forms,Validation,我做了一个登记表,你必须把你所有的个人信息都放进去。 现在,当你提交时,你会发现一些错误,这会使所有的表单都是空的,所以你必须重新填写所有的内容。我如何防止这种情况,让一切都保持原样?(密码可能除外) 这是我的代码: <html> <head> <title>Westpop</title> <link rel="stylesheet" href="opmaak.css"> </head> <body> &

我做了一个登记表,你必须把你所有的个人信息都放进去。 现在,当你提交时,你会发现一些错误,这会使所有的表单都是空的,所以你必须重新填写所有的内容。我如何防止这种情况,让一切都保持原样?(密码可能除外)

这是我的代码:

<html>
<head>
  <title>Westpop</title>
  <link rel="stylesheet" href="opmaak.css">
</head>
<body>
<fblack>
<div id="header"><a href="Index.php"></a></div>

<div id="registreer">
<table cellpadding="5" align="center">
<th colspan="2" align="left">Registeren</th>
<form name="registreren"  method="post" action="registreer.php">
<tr>
    <td><fblackbold>Inloggegevens:<fblackbold></td>
</tr>

<tr>
    <td>Email</td>
    <td><input type="text" size="50" placeholder="email@provider.com" name="email"></td>
</tr>
<tr>
    <td>Wachtwoord</td>
    <td><input type="password" size="50" placeholder="min. 8 tekens, 1 hoofdletter, 1 cijfer" name="wachtwoord"></td>
</tr>
<tr>
    <td><fblackbold>Persoonlijke gegevens:<fblackbold></td>
</tr>
<tr>
    <td>Voornaam</td>
    <td><input type="text" size="50" placeholder="" name="voornaam" ></td>
</tr>
<tr>
    <td>Achternaam</td>
    <td><input type="text" size="50" placeholder="" name="achternaam"></td>
</tr>
<tr>
    <td>Geboorte Datum</td>
    <td><input type="hidden" size="8" name="action" value="submitform" />
    <input type="text" size="50" placeholder="jjjj-mm-dd" name="geboortedatum"></td>

</tr>
<tr>
    <td>Geslacht</td>
    <td>M<input type="radio" size="50" value="m" name="geslacht">
    V<input type="radio" size="50" value="v" name="geslacht"></td>

</tr>
<tr>
    <td>Adres</td>
    <td><input type="text" size="50" placeholder="Straat 00" name="adres"></td>
</tr>
<tr>
    <td>Woonplaats</td>
    <td><input type="text" size="50" placeholder="" name="woonplaats"></td>
</tr>

<tr>
    <td>Telefoonnummer</td>
    <td><input type="text" size="50" placeholder="min. 9 tekens" name="telefoonnummer"></td>
</tr>
<tr>
    <td>Functie</td>
    <td><select name="functie">
<option value="catering">Catering</option>
<option value="muziekpodia">Muziek en podia</option>
<option value="vervoerovernachten">Vervoer en overnachten</option>
<option value="logistiekbeveiliging">Logistiek en beveiliging</option>
<option value="diversen">Diversen</option>
</select></td>
</tr>
<tr align="right">
    <td></td>
    <td><input type="reset" value="Wissen"><input type="submit" name="verzenden" value="Verzenden"></td>
</tr>
</form>
</table>
 <?php
if (isset($_POST['action']) && $_POST['action']=='submitform') {


    $host = "localhost";
    $gebruikersnaam = "root";
    $wachtwoord = "";
    mysql_connect($host, $gebruikersnaam, $wachtwoord);

    $demooistedatabase = "c5g4westpopintranet";
    mysql_select_db($demooistedatabase);

    $achternaam = $_POST["achternaam"];
    $voornaam = $_POST["voornaam"];
    $gbdatum = $_POST["geboortedatum"];
    $email = $_POST["email"];
    $geslacht = $_POST["geslacht"];
    $wachtwoord = $_POST["wachtwoord"];
    $woonplaats = $_POST["woonplaats"];
    $adres = $_POST["adres"];
    $telefoonnummer = $_POST["telefoonnummer"];
    $functie = $_POST["functie"];


    $achternaam = stripslashes($achternaam);
    $voornaam = stripslashes($voornaam);
    $gbdatum = stripslashes($gbdatum);
    $email = stripslashes($email);
    $geslacht = stripslashes($geslacht);
    $wachtwoord = stripslashes($wachtwoord);
    $woonplaats = stripslashes($woonplaats);
    $adres = stripslashes($adres);
    $telefoonnummer = stripslashes($telefoonnummer);
    $functie = stripslashes($functie);


    $query ="INSERT INTO vrijwilliger (voornaam, achternaam, gbdatum, geslacht, wachtwoord, woonplaats, adres, telefoonnummer, functie, activiteitID, groepID, email)
                VALUES('$voornaam','$achternaam','$gbdatum','$geslacht','$wachtwoord','$woonplaats','$adres','$telefoonnummer','$functie',null,null,'$email')";

 $foutloos=true;


if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $wachtwoord) === 0)
{
echo '<fblack>Wachtwoord moet minstens 8 tekens lang zijn, een kleine letter, grote letter en cijfer bevatten.<br><fblack>';
$foutloos = false; 
}

if(preg_match("/^[0-9]{10}+$/", $telefoonnummer) === 0)
{
echo '<fblack>Het telefoonnummer moet 10 cijfers bevatten.<br><fblack>';
$foutloos = false; 
}


if(preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $gbdatum) === 0)
{
echo '<fblack>Geboorte datum moet op dit formaat ingevoerd worden: JJJJ-MM-DD<br><fblack>';
$foutloos = false; 
}

if(preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $email) === 0)
{
echo '<fblack>Email moet hier op lijken: email@provider.com<br><fblack>';
$foutloos = false; 
}


if(preg_match("/^[A-Z][a-zA-Z -]+$/", $voornaam) === 0)
{
echo '<fblack>Voornaam is niet geldig ingevoerd, heeft u een hoofdletter gebruikt?<br><fblack>';
$foutloos = false; 
}


if(preg_match("/^[A-Z][a-zA-Z -]+$/", $achternaam) === 0)
{
echo '<fblack>Achternaam is niet geldig ingevoerd, heeft u een hoofdletter gebruikt?<br><fblack>';
$foutloos = false; 
}


if ($geslacht == '') 
{
echo '<fblack>U heeft uw geslacht niet aangegeven.<br><fblack>';
$foutloos = false; 
}


if(preg_match("/^[a-zA-Z]+\ +[0-9]+$/", $adres) === 0)
{
echo '<fblack>Het adres is verkeerd ingevoerd.<br><fblack>';
$foutloos = false; 
}


if(preg_match("/^[a-zA-Z\s]+$/", $woonplaats) === 0)
{
echo '<fblack>De woonplaats is verkeerd ingevoerd.<br><fblack>';
$foutloos = false; 
}

if ($foutloos == true)
{
mysql_query($query)
or die('<fblack>U staat al in ons systeem<A HREF="javascript:javascript:history.go(-1)"><br><br>Klik hier om terug te gaan</A><fblack>');
echo "<fblack>Uw registratie is succesvol verwerkt!<br>Log <a href='login.php' MEDIA=screen>hier</a> in<fblack>";
}
}
?>
</div>
<?php
include ("html_end.php");
?>

韦斯特波普
注册人
在博客中:
电子邮件
瓦赫特伍德
潘索利克格根斯:
沃纳姆
阿切特南
格布尔特基准面
格斯拉赫特
M
v
阿迪斯
伍恩帕茨
Telefoonnummer
职能
餐饮
穆齐克·恩波迪亚酒店
维沃尔-奥维纳希登酒店
罗吉斯蒂克酒店
戴维森

您可以像这样回显已发布的值:

<input type="text" size="50" placeholder="email@provider.com" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>">

您可以像这样回显发布的值:

<input type="text" size="50" placeholder="email@provider.com" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>">

您必须将表单操作中的值传递回页面

一旦它们在页面上可用,您就可以将它们设置为值。例如:

在进行验证的PHP中,设置

$emailEntered = $_POST['email'];
然后在您的表单中,回显以下值:

<tr>
    <td>Email</td>
    <td><input type="text" size="50" placeholder="email@provider.com" name="email" value="<?php echo $emailEntered; ?>"></td>
</tr>

电子邮件

您必须将值从表单操作传递回页面

一旦它们在页面上可用,您就可以将它们设置为值。例如:

在进行验证的PHP中,设置

$emailEntered = $_POST['email'];
然后在您的表单中,回显以下值:

<tr>
    <td>Email</td>
    <td><input type="text" size="50" placeholder="email@provider.com" name="email" value="<?php echo $emailEntered; ?>"></td>
</tr>

电子邮件

您必须将字段的值设置为用户输入的值,例如

<input type="text" size="50" placeholder="Straat 00" name="adres" value="<?php echo $_POST['adres']; ?>">

您必须将字段的值设置为用户输入的值,例如

<input type="text" size="50" placeholder="Straat 00" name="adres" value="<?php echo $_POST['adres']; ?>">

而不是返回到
历史。继续(-1)
(如果用户不使用javascript,这将不起作用,您应该重新生成包含表单的页面,也就是说,将HTML代码放在名为form.php的文件中,并在出现问题时包含该文件:

include ('form.php');

if (isset($_POST) {
    deal_with_post_data();

    if (something_wrong()) {
        include('form.php');
    } else {
        include('proceed.php');
    }
}
在您的表格中,执行以下操作:

<input type="text" name="foo" value="<?php echo $_POST['foo']; ?>"/>

而不是返回到
历史。继续(-1)
(如果用户不使用javascript,这将不起作用,您应该重新生成包含表单的页面,也就是说,将HTML代码放在名为form.php的文件中,并在出现问题时包含该文件:

include ('form.php');

if (isset($_POST) {
    deal_with_post_data();

    if (something_wrong()) {
        include('form.php');
    } else {
        include('proceed.php');
    }
}
在您的表格中,执行以下操作:

<input type="text" name="foo" value="<?php echo $_POST['foo']; ?>"/>

浏览器不保存您的数据,因此您需要再次自己放置收到的数据

 <?php
 $email = isset($_POST['email']) ? $_POST['email'] : '';
 ?>
<td><input type="text" ... name="email" value="<?php echo $email; ?>"></td>


浏览器不会保存您的数据,所以您需要再次自己放置收到的数据

 <?php
 $email = isset($_POST['email']) ? $_POST['email'] : '';
 ?>
<td><input type="text" ... name="email" value="<?php echo $email; ?>"></td>


您可以使用会话变量:

在页边

<?php
session_start();

//checking if variables are setted
if !(isset($_SESSION("achternaam")){
     $_SESSION["achternaam"]=""
}
//same for all fields
如果成功,最后必须重置变量

$_SESSION["achternaam"] = "";

您可以使用会话变量:

在页边

<?php
session_start();

//checking if variables are setted
if !(isset($_SESSION("achternaam")){
     $_SESSION["achternaam"]=""
}
//same for all fields
如果成功,最后必须重置变量

$_SESSION["achternaam"] = "";

您可以使用javascript验证客户端中的字段,而不是在出现服务器端错误后重新加载值

 <script type='text/javascript'>
   function validate()
  {
    // check for all the text fields if they are null
    var fname= document.getElementById('firstname');
    var lname= document.getElementById('lastname');

    if(fname.value == '')
   {
     // if the field is null it does not submit page and focus() function means
     // cursor will be in that textbox
      alert('Please enter first name');
      fname.focus();
      return false;  

   }

  }
 </script>
//HTML

// the submit button on page 
<input type="submit" name="verzenden" id= 'verzenden' value="verzenden" onclick='return validate();' />
//第页的提交按钮
//javascript

 <script type='text/javascript'>
   function validate()
  {
    // check for all the text fields if they are null
    var fname= document.getElementById('firstname');
    var lname= document.getElementById('lastname');

    if(fname.value == '')
   {
     // if the field is null it does not submit page and focus() function means
     // cursor will be in that textbox
      alert('Please enter first name');
      fname.focus();
      return false;  

   }

  }
 </script>

函数验证()
{
//检查所有文本字段是否为空
var fname=document.getElementById('firstname');
var lname=document.getElementById('lastname');
如果(fname.value=='')
{
//如果字段为空,则不提交页面,focus()函数表示
//光标将位于该文本框中
警报(“请输入名字”);
fname.focus();
返回false;
}
}

您可以使用javascript验证客户端中的字段,而不是在出现服务器端错误后重新加载值

 <script type='text/javascript'>
   function validate()
  {
    // check for all the text fields if they are null
    var fname= document.getElementById('firstname');
    var lname= document.getElementById('lastname');

    if(fname.value == '')
   {
     // if the field is null it does not submit page and focus() function means
     // cursor will be in that textbox
      alert('Please enter first name');
      fname.focus();
      return false;  

   }

  }
 </script>
//HTML

// the submit button on page 
<input type="submit" name="verzenden" id= 'verzenden' value="verzenden" onclick='return validate();' />
//第页的提交按钮
//javascript

 <script type='text/javascript'>
   function validate()
  {
    // check for all the text fields if they are null
    var fname= document.getElementById('firstname');
    var lname= document.getElementById('lastname');

    if(fname.value == '')
   {
     // if the field is null it does not submit page and focus() function means
     // cursor will be in that textbox
      alert('Please enter first name');
      fname.focus();
      return false;  

   }

  }
 </script>

函数验证()
{
//检查所有文本字段是否为空
var fname=document.getElementById('firstname');
var lname=document.getElementById('lastname');
如果(fname.value=='')
{
//如果字段为空,则不提交页面,focus()函数表示
//光标将位于该文本框中
警报(“请输入名字”);
fname.focus();
返回false;
}
}

我不确定这是否适用于您,但通常我的表单操作在同一页上,因此当出现错误时,我会将值回显到“值”属性中。因为这不是您的情况,您可以将操作更改到同一页,并在该页中执行类似操作:

<?php
if (sizeof($_POST)) {
    require 'the_action_you_have_now.php';
    // If it succeeds, it would redirect to another page and exit, otherwise, just continue, and set a variable with a message that says there's an error.
}
?>

我不确定这是否适用于您,但通常我的表单操作在同一页上,因此当出现错误时,我会在“值”属性中回显值。因为这不是您的情况,您可以将操作更改到同一页,并在该页中执行类似操作:

<?php
if (sizeof($_POST)) {
    require 'the_action_you_have_now.php';
    // If it succeeds, it would redirect to another page and exit, otherwise, just continue, and set a variable with a message that says there's an error.
}
?>

您在这些字段中没有
请尝试javascript,它将帮助您验证页面您在这些字段中没有
请尝试javascript,它将帮助您验证页面