Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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_Variables_Login_Isset - Fatal编程技术网

Php 尝试填写注册字段时出错

Php 尝试填写注册字段时出错,php,variables,login,isset,Php,Variables,Login,Isset,我正在尝试用PHP为学校作业创建一个登录和注册系统,但它目前并没有真正起作用 问题是,它会生成一个错误,指出字段为空,即使在您用数据填充字段时也是如此,因此它不应该给出此错误 守则: <html> <head> <title>Music Database</title> <link rel="stylesheet" href="layout.css" type="text/css" /> <?php

我正在尝试用PHP为学校作业创建一个登录和注册系统,但它目前并没有真正起作用

问题是,它会生成一个错误,指出字段为空,即使在您用数据填充字段时也是如此,因此它不应该给出此错误

守则:

    <html>
<head>
    <title>Music Database</title>
    <link rel="stylesheet" href="layout.css" type="text/css" />
    <?php
        // Verbinden met de database //
        include('connect.php');

        // Registreer data verkrijgen en in variabelen zetten //
        if(isset($_POST['r_submit'])){
            $r_username = $_POST['r_username']; 
            $r_password = $_POST['r_password'];
            $confirm_r_password = $_POST['confirm_r_password']; 
            $r_name = $_POST['r_name']; 
            $r_surname = $_POST['r_surname'];
            $r_birth = $_POST['r_dateofbirth'];
            $r_mail = $_POST['r_mail'];
        }
    ?>
</head>
<body>
    <div id="login">
        <form name="login" action="login.php" method="post">
            <p>Login: <input class="input" type="text" name="username" value="Username" />
            <input id="password" type="password" name="password" value="Password" /></p>
            <div><a class="link" href="register.php">Register here!</a></div>
            <p align="center"><input class="submit" type="submit" name="login_submit" value="Submit" /></p>
        </form>
    </div>
    <div id="header">
        <a class="link" href="index.php">Music Database</a>
    </div>
    <div id="search">
        <form name="search" action="search.php" method="post">
            <p>Search for: <input class="input" type="text" name="search" value="<?php if(isset($_POST['search'])) print $_POST['search']; ?>" />
            <input class="submit" type="submit" name="search_submit" value="Submit" /></p>
            <p>Artist: <input type="checkbox" name="artistsearch" checked /> 
            Album: <input type="checkbox" name="albumsearch" /> 
            Song: <input type="checkbox" name="songsearch" /> 
            Genre: <input type="checkbox" name="genresearch" /></p>
        </form>
    </div>
    <div id="wrapper"><br /></div>
    <div id="content">
        <h1>Register down here please:</h1>
        <table id="wrap_table">
            <tr>
                <td>
                    <div id="reg_content">
                    <div id="reg_form">
                        <form name="register_login" action="register.php" method="post">
                            <fieldset>
                            <legend>Login Data: </legend>
                                <table class="r_table">
                                    <tr>
                                        <td>Username<sup>*</sup>: </td>
                                        <td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; }  ?>"/></td>
                                        <?php
                                            if(isset($_POST['r_submit'])){
                                                if(!isset($r_username)){
                                                    echo "<td>Error: No Username has been entered!</td>";
                                                }
                                            }
                                        ?>
                                    </tr>
                                    <tr>
                                        <td>Password<sup>*</sup>: </td>
                                        <td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; }  ?>"/></td>
                                        <?php
                                            if(isset($_POST['r_submit'])){
                                                if(!isset($r_password)){
                                                    echo "<td>Error: No Password has been entered!</td>";
                                                }
                                            }
                                        ?>
                                    </tr>
                                    <tr>
                                        <td>Confirm Password<sup>*</sup>: </td>
                                        <td><input class="input" type="password" name="confirm_r_password"  value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; }  ?>"/></td>
                                        <?php
                                            if(isset($confirm_password)){
                                                if($confirm_r_password != $r_password){
                                                    echo "<td>Error: The passwords don't match!</td>";
                                                }
                                            }
                                        ?>
                                    </tr>
                                </table>
                            </fieldset>
                        </form>
                    </div>
                </td>
                <td>
                    <div id="reg_form">
                        <form name="register_personal" action="register.php" method="post">
                            <fieldset>
                            <legend>Personal Data: </legend>
                                <table class="r_table_personal">
                                    <tr>
                                        <td>Name: </td>
                                        <td><input class="input" type="text" name="r_name" value=""/></td>                              
                                    </tr>
                                    <tr>
                                        <td>Surname: </td>
                                        <td><input class="input" type="text" name="r_surname" value=""/></td>
                                    </tr>
                                    <tr>
                                        <td>Date of Birth: </td>
                                        <td><input class="input" type="text" name="r_dateofbirth"  value=""/></td>
                                    </tr>
                                    <tr>
                                        <td>E-mail<sup>*</sup>: </td>
                                        <td><input class="input" type="text" name="r_mail" value="<?php if(isset($r_mail)){ print $_POST['r_mail']; } ?>"/></td>
                                        <?php
                                            if(isset($_POST['r_submit'])){
                                                if(!isset($r_mail)){
                                                    echo "<td>Error: No E-mail has been entered!</td>";
                                                }
                                            }
                                        ?>
                                    </tr>
                                </table>
                            </fieldset>
                        </form>
                    </div>
                </div>
                </td>
            </tr>
            <tr>
                <td>Fields with an asterisk<sup>*</sup> are required for registry!
                    <div id="reg_content">
                        <form name="submit_registry" action="register.php" method="post">
                            <input class="submit" type="submit" name="r_submit" value="Submit!" />
                        </form>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="footerbreak"><br /></div>
    <div id="footer"> &copy; Jorik ter Molen &amp; Camiel Collet, 2011.</div>
</body> 
你有你的电脑吗

您还可以调试$\u POST global,以查看数据命中脚本时发生的情况

var_dump($_POST);

那么在代码后面的第二个php文件中包含第一个表单页面,对吗

首先,在PHP文件中,您应该添加所有

if(isset($_POST['submit'])){
分段为一个:

if(isset($_POST['submit'])){
    $r_username = $_POST['r_username'];
    $r_password = $_POST['r_password'];
    $confirm_r_password = $_POST['confirm_r_password']; 
    $r_name = $_POST['r_name']; 
    $r_surname = $_POST['r_surname'];
    $r_birth = $_POST['r_dateofbirth'];
    $r_mail = $_POST['r_mail'];
} 
您的问题很可能出现在$\u POST['submit']中,因为您有两个检查,一个用于$\u POST['submit'],另一个用于$\u POST['r\u submit']

除非您以两种方式发送,否则我建议您更改PHP文件以检查“r\u submit”

更新: 尝试将表单放入register.php页面,使其看起来像这样:

<?php
    if(isset($_POST['r_submit'])){
        $r_username = $_POST['r_username'];
        $r_password = $_POST['r_password'];
        $confirm_r_password = $_POST['confirm_r_password']; 
    } 

?>

<form action="register.php" method="post">

    <td>Username<sup>*</sup>: </td>
        <td><input class="input" type="text" name="r_username" value="<?php     if(isset($r_username)){ print $_POST['r_username']; }  ?>"/></td>
    <?php
        if(isset($_POST['r_submit'])){
            if(!isset($r_username)){
                echo "<td>Error: No Username has been entered!</td>";
            }
        }
    ?>
</tr>
<tr>
    <td>Password<sup>*</sup>: </td>
    <td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; }  ?>"/></td>
    <?php
        if(isset($_POST['r_submit'])){
            if(!isset($r_password)){
                echo "<td>Error: No Password has been entered!</td>";
            }
        }
    ?>
</tr>
<tr>
    <td>Confirm Password<sup>*</sup>: </td>
    <td><input class="input" type="password" name="confirm_r_password"  value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; }  ?>"/></td>
    <?php
        if(isset($confirm_password)){
            if($confirm_r_password != $r_password){
                echo "<td>Error: The passwords don't match!</td>";
            }
        }
    ?>
   </tr>

<input name="r_submit" type="submit" value="Submit" />   
</form>
解决方案:
在php检查匹配密码的第82行附近,将其替换为:

<?php
if(isset($_POST['r_submit'])){
    if($confirm_r_password != $r_password)
    {
          echo "<td>Error: The passwords don't match!</td>";
    }
 }
 ?>

虽然这只是一个基本检查,没有什么安全性,因为用户可以将两个密码保留为空,并且它们仍然匹配。

这两段代码是否在不同的php文件中?执行命令是什么?如果在第二段代码之前执行html部分,则会出现错误,因为$r_username、$r_password等变量没有定义PHP部分首先执行,然后执行html,html部分也在表单中,但是因为代码太庞大,所以把表单拿走了:如果人们想看的话,P仍然可以添加它。将它更改为正确的r_submit,但是现在PHP本身生成了另外两个错误:注意:未定义索引:第11行C:\xampp\htdocs\MusicDatabase\register.PHP中的r\u用户名注意:第12行C:\xampp\htdocs\MusicDatabase\register.PHP中的未定义索引:第12行C:\xampp\htdocs\MusicDatabase\register.PHP中的确认r\u密码第13行等等。您的表单有问题,因为它无法识别您发送的post变量。你在表单声明中使用method=post吗?检查更新后的答案并告诉我们如果仍然有错误PHP和HTML已经在同一个文档中,我将发布整个代码,也许这会解决问题;给你。您的问题是,提交按钮的格式与注册输入文本框的格式不同。将所有用于注册的文本框和提交按钮放在同一个表单中。var_dump生成以下行:array1{[r_submit]=>string7 submit!}即使数据已经放在文本字段中,所以我猜_POST从未收到用户名等。
<?php
if(isset($_POST['r_submit'])){
    if($confirm_r_password != $r_password)
    {
          echo "<td>Error: The passwords don't match!</td>";
    }
 }
 ?>