Php和sqlite注册表

Php和sqlite注册表,php,sqlite,post,Php,Sqlite,Post,我是php和sqlite新手,我正在尝试修改网站的注册表单。我做了我认为是所有必要的改变,但我现在不能让它工作,因为当我使用电子邮件注册它告诉我它已经存在。表单之前使用了用户名,并检查用户名是否已存在。如果有,则会显示一条消息。现在我不想使用用户名,只想使用电子邮件注册,即使数据库是空的,它总是告诉我电子邮件已经存在。我只留下了注册邮件,以便更容易理解。但即便如此,问题依然存在 我认为在检查数据库时出现了问题,但我不知道问题出在哪里。我不太了解php页面之间的流程,所以如果有人能帮我澄清到底发生

我是php和sqlite新手,我正在尝试修改网站的注册表单。我做了我认为是所有必要的改变,但我现在不能让它工作,因为当我使用电子邮件注册它告诉我它已经存在。表单之前使用了用户名,并检查用户名是否已存在。如果有,则会显示一条消息。现在我不想使用用户名,只想使用电子邮件注册,即使数据库是空的,它总是告诉我电子邮件已经存在。我只留下了注册邮件,以便更容易理解。但即便如此,问题依然存在

我认为在检查数据库时出现了问题,但我不知道问题出在哪里。我不太了解php页面之间的流程,所以如果有人能帮我澄清到底发生了什么,我将不胜感激。这是注册页面的代码

Participate.php:

<hr class="structure" />
<h1 class="out">Main content</h1>
<div class="eb1"> 
  <!--TYPO3SEARCH_begin-->
  <h2 class="out">Topinformationen</h2>
  <!--TYPO3SEARCH_end--> 
</div>
<div class="eb2"> 
  <!--TYPO3SEARCH_begin-->
  <h2>Participate</h2>
<p>Please register.</p>
  <!-- ###LOGIN_FORM### -->
<div class="box big form">

<form id="participateForm" action="#" target="_top" onSubmit="return checkform();" method="post" name="participate">
    <fieldset class="nolegend">
        <legend>Particpate</legend>
        <div>
            <label for="email">
                <span> Email:* <?php echo isset($_POST['email']) ? '<strong>The email &ldquo;' .$_POST['email']. '&rdquo; already exists. </strong>' : ''; ?></span><input type="email" name="email" required/>
            </label>
        </div>
    </fieldset>
    <div class="morelink">
        <p><input type="submit" name="submit" value="Participate" onclick="show('form'); return FALSE;"/></p>
    </div>
</form>
</div><!-- box big form -->
</div>
所以我认为它正在发生的是这样的,如果有人告诉我我是否完全迷路了,或者如果我需要把代码的其他部分解释清楚,我将不胜感激。因此,particiate.php使用这个post变量上的email send调用自己。不知何故,我不知道如何调用functions.php代码,这个register函数用于检查电子邮件是否存在,如果不存在,则将其添加到数据库中。问题是它不起作用。此代码以前使用用户名而不是电子邮件时有效。当时的注册确实有效

顺便说一下,在particiate.php代码中调用的checkform()函数就是这样做的

function checkform()
  {
                if (document.participate.email.value ==  "")
                 {
                      alert('Please enter an email.');
                      document.participate.email.focus();
                      return false;
                }

  }
编辑1:

原始代码particiate.php

 <hr class="structure" />
<h1 class="out">Main content</h1>
<div class="eb1"> 
  <!--TYPO3SEARCH_begin-->
  <h2 class="out">Topinformationen</h2>
  <!--TYPO3SEARCH_end--> 
</div>
<div class="eb2"> 
  <!--TYPO3SEARCH_begin-->
  <h2>Participate</h2>
<p>Register here.</p>
  <!-- ###LOGIN_FORM### -->
<div class="box big form">

<form id="participateForm" action="#" target="_top" onSubmit="return checkform();" method="post" name="participate">
    <fieldset class="nolegend">
        <legend>Particpate</legend>
        <div>
            <label for="user">
                <span> Username: <?php echo isset($_POST['username']) ? '<strong>The username &ldquo;' .$_POST['username']. '&rdquo; already exists. Please chose a different one.</strong>' : ''; ?></span><input type="text" name="username" required/>
            </label>
        </div>
        <div>
            <label for="pass">
                <span>Password (at least 8 characters):</span><input type="password" name="password" required pattern="^([0-9a-zA-Z]{8,20})"/>
            </label>
        </div>
        <div>
            <label for="passRT">
                <span>Re-type Password: </span><input type="password" name="passwordRT" required pattern="^([0-9a-zA-Z]{8,20})"/>
            </label>
        </div>
        <div>
            <label for="email">
                 Email: <input type="email" name="email" required placeholder="Enter a valid email address"> 
            </label>
        </div>
        <div>
            <label for="birth">
                <span>Year of Birth (yyyy): </span><input type="text" name="YearOfBirth" value="<?php echo isset($_POST['YearOfBirth']) ? htmlspecialchars($_POST['YearOfBirth']) : ''; ?>" required pattern="\d{4}"/>
            </label>
        </div>
        <div>
            <label for="adress">
                Home adress (Street, ZIP-Code, City): <input name="adress" type="text"  value="<?php echo isset($_POST['adress']) ? htmlspecialchars($_POST['adress']) : ''; ?>" required/>
            </label>
        </div>
        <div>

                <table><tr><td>Gender:</td>
                <td align="center"><label><input id="Female" type="radio" name="sex" value="1" required/>Female</label></td><td align="center"><label><input type="radio"  name="sex" value="2"  />Male</label></td><td align="center"></td></tr></table>
        </div>
        <div>
        <label for"agreetext">
        <textarea rows="10" readonly="readonly" id="agreetext" name="agreetext"> Privacy Policy: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ac vulputate risus, eu scelerisque elit. Aenean eget ligula et est rutrum hendrerit at sed sapien. Nunc nunc dolor, sagittis at enim eget, imperdiet cursus magna. Nam fringilla mauris id tellus placerat, ut tincidunt urna semper. Vestibulum vel blandit nisi, nec pulvinar dolor. Fusce vitae faucibus enim, a aliquet purus. Vivamus dapibus aliquet massa ut rhoncus. Nulla sit amet fermentum neque. Integer a velit vitae mauris convallis semper. Sed consequat consequat nibh, a ultricies nisi efficitur vitae.

Terms and Conditions: Aliquam aliquam condimentum quam, sed aliquet felis suscipit in. Nulla at ex at ex scelerisque commodo eget eget dui. Quisque nunc ante, cursus ut turpis et, ornare rutrum mi. In eget quam bibendum, egestas massa quis, porttitor arcu. Phasellus vel consequat turpis, non imperdiet augue. Donec euismod, sem sed pretium elementum, libero dolor venenatis lorem, quis tincidunt odio nunc quis diam. Maecenas nec risus vitae tortor pulvinar elementum. Nam convallis porttitor tellus, ac ultricies purus pretium venenatis. Curabitur condimentum sapien mauris, ac bibendum leo pulvinar elementum. Vestibulum ante sem, posuere a nisl eu, maximus elementum diam.</textarea>
</label>
</div>
<div><p><input onchange="this.setCustomValidity(validity.valueMissing ? 'Please indicate that you accept the privacy policy' : '');" id="privacy_policy" type="checkbox" required name="privacy_policy"> I accept the privacy policy</p><p>
    <input onchange="this.setCustomValidity(validity.valueMissing ? 'Please indicate that you accept the Terms and Conditions' : '');" id="terms" type="checkbox" required name="terms"> I accept the       Terms and Conditions</p></div>
    </fieldset>
    <div class="morelink">
        <p><input type="submit" name="submit" value="participate" onclick="show('form'); return FALSE;"/></p>
    </div>
</form>
</div><!-- box big form -->
</div>

<!-- eb2 --> 
编辑3:

Login.php代码

<hr class="structure" />
<h1 class="out">Main content</h1>
<div class="eb1"> 
  <!--TYPO3SEARCH_begin-->
  <h2 class="out">Topinformationen</h2>
  <!--TYPO3SEARCH_end--> 
</div>
<div class="eb2"> 
  <!--TYPO3SEARCH_begin-->
  <h2>Login</h2>
  <!-- ###LOGIN_FORM### -->
  <?PHP
  if($_GET["info"]==1){
  echo '<p><strong>Congratulations!</strong> Your registration has been successfully submitted. You can login now.</p>';
  }
  ?>
<div class="box big form">


<form id="loginForm" action="#" target="_top" method="post" >
    <fieldset class="nolegend">
        <legend>Login</legend>
        <div>
            <label for="user">
                <span class="toplabel">Username: </span><br class="none" />
                <input type="text" name="username" required/>
            </label><br class="none" />
        </div>
        <div>
            <label for="pass">
                <span class="toplabel">Password: </span><br class="none" />
                <input type="password" id="lpw" name="password" required/>
            </label><br class="none" />
        </div>

    </fieldset>
    <div class="morelink">
        <p><input type="submit" name="submit" value="login" onclick="show('form'); return FALSE;"/></p>
    </div>
</form>
</div><!-- box big form -->

    <!--TYPO3SEARCH_end--> 
</div>

主要内容 Topinformationen 登录 登录 用户名:

密码:


您的表单调用了
checkform()
,但无论何时设置
$\u POST['email']
都会发送“已存在”消息,但在发布表单时总是会设置该消息。在您试图修改代码之前,您是否拥有该代码?我将把particiate.php中的原始完整代码添加到edit中,但基本上是一样的。奇怪的是,它工作得很好。要澄清的是,它是表单的
标签
电子邮件&ldquo$_发布['email'].'&rdquo;已经存在。
您看到的是输出,还是SQLite抱怨已经存在重复的键和记录?根据
SELECT
查询返回的内容,
if($count!=1)
可能会出现问题,导致执行
INSERT
,并且可能在SQLite中出现密钥冲突。是的,显示的是表单标记。如果($count!=1)部分在原来的部分上没有出现任何问题,但是您建议更改它吗?哇,很高兴您找到了它。如果不能在生产环境中调试代码,我很难发现这一点。现在您已经解决了这个问题,您应该开始学习使用PDO。
postvar()
函数无法防止SQL注入,使此代码容易被篡改(甚至可能以管理员权限登录)。开始您的表单调用
checkform()
,但只要设置了
$\u POST['email']
,就会发送“已存在”消息,但它将始终在表单发布时设置。在您试图修改代码之前,您是否拥有该代码?我将把particiate.php中的原始完整代码添加到edit中,但基本上是一样的。奇怪的是,它工作得很好。要澄清的是,它是表单的
标签
电子邮件&ldquo$_发布['email'].'&rdquo;已经存在。
您看到的是输出,还是SQLite抱怨已经存在重复的键和记录?根据
SELECT
查询返回的内容,
if($count!=1)
可能会出现问题,导致执行
INSERT
,并且可能在SQLite中出现密钥冲突。是的,显示的是表单标记。如果($count!=1)部分在原来的部分上没有出现任何问题,但是您建议更改它吗?哇,很高兴您找到了它。如果不能在生产环境中调试代码,我很难发现这一点。现在您已经解决了这个问题,您应该开始学习使用PDO。
postvar()
函数无法防止SQL注入,使此代码容易被篡改(甚至可能以管理员权限登录)。开始您的表单调用
checkform()
,但只要设置了
$\u POST['email']
,就会发送“已存在”消息,但它将始终在表单发布时设置。在您试图修改代码之前,您是否拥有该代码?我将把particiate.php中的原始完整代码添加到edit中,但基本上是一样的。奇怪的是,它工作得很好。要澄清的是,它是表单的
标签
电子邮件&ldquo$_发布['email'].'&rdquo;已经存在。
您看到的是输出,还是SQLite抱怨已经存在重复的键和记录?根据
SELECT
查询返回的内容,
if($count!=1)
可能会出现问题,导致执行
INSERT
,并且可能在SQLite中出现密钥冲突。是的,显示的是表单标记。if($count!=1)部分在原始部分上没有给出任何问题,但是您会建议吗
 <hr class="structure" />
<h1 class="out">Main content</h1>
<div class="eb1"> 
  <!--TYPO3SEARCH_begin-->
  <h2 class="out">Topinformationen</h2>
  <!--TYPO3SEARCH_end--> 
</div>
<div class="eb2"> 
  <!--TYPO3SEARCH_begin-->
  <h2>Participate</h2>
<p>Register here.</p>
  <!-- ###LOGIN_FORM### -->
<div class="box big form">

<form id="participateForm" action="#" target="_top" onSubmit="return checkform();" method="post" name="participate">
    <fieldset class="nolegend">
        <legend>Particpate</legend>
        <div>
            <label for="user">
                <span> Username: <?php echo isset($_POST['username']) ? '<strong>The username &ldquo;' .$_POST['username']. '&rdquo; already exists. Please chose a different one.</strong>' : ''; ?></span><input type="text" name="username" required/>
            </label>
        </div>
        <div>
            <label for="pass">
                <span>Password (at least 8 characters):</span><input type="password" name="password" required pattern="^([0-9a-zA-Z]{8,20})"/>
            </label>
        </div>
        <div>
            <label for="passRT">
                <span>Re-type Password: </span><input type="password" name="passwordRT" required pattern="^([0-9a-zA-Z]{8,20})"/>
            </label>
        </div>
        <div>
            <label for="email">
                 Email: <input type="email" name="email" required placeholder="Enter a valid email address"> 
            </label>
        </div>
        <div>
            <label for="birth">
                <span>Year of Birth (yyyy): </span><input type="text" name="YearOfBirth" value="<?php echo isset($_POST['YearOfBirth']) ? htmlspecialchars($_POST['YearOfBirth']) : ''; ?>" required pattern="\d{4}"/>
            </label>
        </div>
        <div>
            <label for="adress">
                Home adress (Street, ZIP-Code, City): <input name="adress" type="text"  value="<?php echo isset($_POST['adress']) ? htmlspecialchars($_POST['adress']) : ''; ?>" required/>
            </label>
        </div>
        <div>

                <table><tr><td>Gender:</td>
                <td align="center"><label><input id="Female" type="radio" name="sex" value="1" required/>Female</label></td><td align="center"><label><input type="radio"  name="sex" value="2"  />Male</label></td><td align="center"></td></tr></table>
        </div>
        <div>
        <label for"agreetext">
        <textarea rows="10" readonly="readonly" id="agreetext" name="agreetext"> Privacy Policy: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ac vulputate risus, eu scelerisque elit. Aenean eget ligula et est rutrum hendrerit at sed sapien. Nunc nunc dolor, sagittis at enim eget, imperdiet cursus magna. Nam fringilla mauris id tellus placerat, ut tincidunt urna semper. Vestibulum vel blandit nisi, nec pulvinar dolor. Fusce vitae faucibus enim, a aliquet purus. Vivamus dapibus aliquet massa ut rhoncus. Nulla sit amet fermentum neque. Integer a velit vitae mauris convallis semper. Sed consequat consequat nibh, a ultricies nisi efficitur vitae.

Terms and Conditions: Aliquam aliquam condimentum quam, sed aliquet felis suscipit in. Nulla at ex at ex scelerisque commodo eget eget dui. Quisque nunc ante, cursus ut turpis et, ornare rutrum mi. In eget quam bibendum, egestas massa quis, porttitor arcu. Phasellus vel consequat turpis, non imperdiet augue. Donec euismod, sem sed pretium elementum, libero dolor venenatis lorem, quis tincidunt odio nunc quis diam. Maecenas nec risus vitae tortor pulvinar elementum. Nam convallis porttitor tellus, ac ultricies purus pretium venenatis. Curabitur condimentum sapien mauris, ac bibendum leo pulvinar elementum. Vestibulum ante sem, posuere a nisl eu, maximus elementum diam.</textarea>
</label>
</div>
<div><p><input onchange="this.setCustomValidity(validity.valueMissing ? 'Please indicate that you accept the privacy policy' : '');" id="privacy_policy" type="checkbox" required name="privacy_policy"> I accept the privacy policy</p><p>
    <input onchange="this.setCustomValidity(validity.valueMissing ? 'Please indicate that you accept the Terms and Conditions' : '');" id="terms" type="checkbox" required name="terms"> I accept the       Terms and Conditions</p></div>
    </fieldset>
    <div class="morelink">
        <p><input type="submit" name="submit" value="participate" onclick="show('form'); return FALSE;"/></p>
    </div>
</form>
</div><!-- box big form -->
</div>

<!-- eb2 --> 
function register()
{
    global $open, $settings, $db_usr;

    $username = postvar("username");
    $pw = postvar("password");
    $pww = postvar("passwordRT");
    $year = postvar("YearOfBirth");
    $adress = postvar("adress");
    $sex = postvar("sex");
    $email = postvar("email");
    $privacy = postvar("privacy_policy");
    $terms = postvar("terms");

    //if($privacy && $terms)
    if(TRUE)
    {
        $query = "SELECT * FROM usr_data WHERE username='".$username."'";
        $res_usr = $db_usr->prepare($query);
        $res_usr->execute();
        $count=$res_usr->fetchColumn();

        echo $count;


        if($count!=1){

        $query ="INSERT INTO usr_data (username, password, regtime, status, sessionID, birth, sex, email, home) VALUES ('".$username."', '".md5($pw)."', '".time()."','0', 'new', '".intval($year)."','".intval($sex)."','".$email."' ,'".$adress."')"; 
        $db_usr->query($query);


        header("Location: ".$settings["Main"]."?open=Login&info=1");
        }
        else
        {
        //$open="Login_Failed";
        }
    }
}
<hr class="structure" />
<h1 class="out">Main content</h1>
<div class="eb1"> 
  <!--TYPO3SEARCH_begin-->
  <h2 class="out">Topinformationen</h2>
  <!--TYPO3SEARCH_end--> 
</div>
<div class="eb2"> 
  <!--TYPO3SEARCH_begin-->
  <h2>Login</h2>
  <!-- ###LOGIN_FORM### -->
  <?PHP
  if($_GET["info"]==1){
  echo '<p><strong>Congratulations!</strong> Your registration has been successfully submitted. You can login now.</p>';
  }
  ?>
<div class="box big form">


<form id="loginForm" action="#" target="_top" method="post" >
    <fieldset class="nolegend">
        <legend>Login</legend>
        <div>
            <label for="user">
                <span class="toplabel">Username: </span><br class="none" />
                <input type="text" name="username" required/>
            </label><br class="none" />
        </div>
        <div>
            <label for="pass">
                <span class="toplabel">Password: </span><br class="none" />
                <input type="password" id="lpw" name="password" required/>
            </label><br class="none" />
        </div>

    </fieldset>
    <div class="morelink">
        <p><input type="submit" name="submit" value="login" onclick="show('form'); return FALSE;"/></p>
    </div>
</form>
</div><!-- box big form -->

    <!--TYPO3SEARCH_end--> 
</div>