Php和sqlite注册表

时间:2015-06-06 14:21:17

标签: php sqlite post

我是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>

因此,如果我在您点击“参与”按钮时理解正确,则该页面会自动调用(action =&#34;#&#34;),并将该电子邮件作为帖子变量。问题是这个特定页面上没有任何内容使用该变量,所以我想这段代码正在重新加载index.php页面,该页面以这样的方式开始。

index.php:

<?PHP
    //Session wird gestartet
    session_start();
        //Includ PHP functions
    @include("./data/php/functions.php");
        //Funktionen werden ausgeführt
    if(isset($_GET['do']))
    {
    if($_GET["do"]=="logout"){
        logout();
     }
    }
     else if (!empty($_GET["email"])&& !session()){
        login($_GET["email"]);
     }
     if(postvar("submit")=="login" && !session()){
         login(0,0);
     }
     else if (postvar("submit")=="participate" && !session()){
         register();
     }
     else if (postvar("submit")=="emote" && session()){
         saveMood();
     }

?>

在这个functions.php中,index.php页面中包含的代码是访问数据库的函数。所以这些功能中有两个就是这些。

functions.php:

function postvar($var)
{
    if (isset($_POST[$var])){
    $erg = $_POST["$var"];
    $erg = trim($erg);
    }
    else 
    $erg=NULL;
    return $erg;
}

function register()
{
    global $open, $settings, $db_usr;

    $email = postvar("email");

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

        if($count!=1){

        $query ="INSERT INTO usr_data (email, regtime, status, sessionID) VALUES ('".$email."', '".time()."','0', 'new')";
        $db_usr->query($query);

        header("Location: ".$settings["Main"]."?open=Login&info=1");
        }
        else
        {
        //$open="Login_Failed";
        }
    }
}

所以我认为它发生的是这个,如果有人告诉我,我是否完全迷失了,或者我是否需要将其他部分代码澄清,我将不胜感激。所以,visit.php通过发送此post变量的电子邮件调用自己。不知何故,我并不确切地知道如何调用functions.php代码,这个寄存器函数用于检查电子邮件是否存在,如果不存在,则将其添加到数据库中。问题是它无法正常工作。此代码之前有效,而不是使用用户名的电子邮件。那时的注册确实有效。

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

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

  }

编辑1:

原始代码参与.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 --> 

编辑2:

原始Functions.php代码

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";
        }
    }
}

编辑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>

0 个答案:

没有答案