duanheyi7147 2013-05-31 05:51
浏览 58
已采纳

通过维护用户在数据库中设置用户的电子邮件

This is how I want to find out about the user exists in the database but it will constantly keep themselves it exists when it does not do it.

What I want out of this code is to get the knowledge about the user in the database if it does not make it must clearly say it :)

}
    else
        {
            $email_1 = $_post["email"];
            $result = $this->mysqli->query("SELECT * FROM bruger WHERE email='$email_1'");
            if(mysqli_num_rows($resut) > 0)
            {
//code here!
}
        else
        {
        ?>
        <div class="article-main-content">
            <div class="alert-message" style="background-color:#c22525;"><span class="icon-text">&#9888;</span><span class="alert-content">Email Findes på hjemmesiden</span><a href="#" class="destroy-button"></a></div>
        </div>
        <?php
        }
    }
}

and i have try its here:

$email = $_post["email"]
    foreach($this->mysqli->query("SELECT * FROM `bruger` WHERE email='$email'") as $row) {
              if ($row['email'] !== $email) {

here are all my html code:

<form action="#" enctype="multipart/form-data" method="post">
    <table width="100%" cellpadding="5" cellspacing="5">
        <tr>
            <td><p>Email</p></td>
            <td><input type="text" name="email" class="ned_input"></td>
        </tr>
        <tr>
            <td><p>Adgangskode</p></td>
            <td><input type="password" name="password_adgangskode_1" class="ned_input"></td>
        </tr>
        <tr>
            <td><p>Adgangskode Gentag</p></td>
            <td><input type="password" name="password_adgangskode_2" class="ned_input"></td>
        </tr>
        <tr>
            <td><p>Fornavn</p></td>
            <td><input type="text" name="fornavn" class="ned_input"></td>
        </tr>
        <tr>
            <td><p>Efternavn</p></td>
            <td><input type="text" name="efternavn" class="ned_input"></td>
        </tr>
        <tr>
            <td><p>Profilbillede</p></td>
            <td><input type="file" name="file" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" name="opret" value="Opret bruger" style="margin-top:10px;"></td>
        </tr>
    </table>
</form>

EIDT HERE

if ($stmt = $this->mysqli->prepare("SELECT `id` FROM `bruger` WHERE `email`"))
             {
             $stmt->bind_param('s', $email_indhold);
             $email_indhold = $_POST["email"];


             $stmt->execute();
             $stmt->store_result();
             $stmt->bind_result($id);
             $stmt->fetch();
             $count = $stmt->num_rows;
             $stmt->close();

             if($count > 0)
             {
  • 写回答

2条回答 默认 最新

  • douchaqi3369 2013-05-31 06:06
    关注

    look the algorithm for this

    PHP end

    1. collect POST data first and sanitize the input.
    2. check for the email

      SELECT email FROM table WHERE email = '$post_email' LIMIT 1

    3. if result is not empty then go forward

    4. else gives alert of duplicate entry

    Database end

    to add UNIQUE KEY constraint on your db

    ALTER TABLE  <table name >
    ADD CONSTRAINT uniqueEmail UNIQUE (< `email column` > )
    

    using unique constraint will safe your table,it will give error when someone try to enter duplicate email.So when you execute INSERT query for the table, check what**mysqli_query** returns ( see below )

    $qry = "SELECT INTO table (whatever) VALUE (whatever)";
    $done = mysqli_query($qry);
    

    check $done, if everything goes fine then it will return TRUE otherwise it will gives mysql_error( may be 1064), so by this way you can also prevent to stop duplicate email address

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘