douwuying4709 2017-10-29 15:35
浏览 104
已采纳

如何让用户在php中选择不同的颜色模式

<form action="" method="post" id="customer-register">
<table align="center">
 <div id="container">
    <h1>Welcome to Registration Page!</h1>

       <td>Full Name:</td>
       <td><input type="text" name="fname" placeholder="enter your name">
</td>
    </tr>

    <tr>
       <td>Username:</td>
       <td><input type="text" name="uname" placeholder="enter your 
username"></td>
    </tr>

    <tr>
       <td>Email:</td>
       <td><input type="text" name="email" placeholder="enter your email">
</td>
    </tr>

    <tr>
       <td>Select your Password:</td>
       <td><input type="color" name="color1" value="#ff0000"><input 
type="color" name="color2" value="#ff0000"><input type="color" name="color3" 
value="#ff0000"><input type="color" name="color4" value="#ff0000"><input 
type="color" name="color5" value="#ff0000"></td>
    </tr>
       <td><input type="submit" name="submit" value="Register"></td>
 </tr>    
</body>
</html>

This is my code for my register.php project. As you can see, I am not using text password, instead im allowing user to pick 5 type of colour to register.My question is there a source code for me to make sure that user do not enter the same color pattern as other user which have entered and saved in the database?

 if(isset($_POST['submit'])){
   $fname=$_POST['fname'];
   $uname=$_POST['uname'];
   $email=$_POST['email'];
   $pass1=$_POST['color1'];
   $pass2=$_POST['color2'];
   $pass3=$_POST['color3'];
   $pass4=$_POST['color4'];
   $pass5=$_POST['color5'];
   $register_query = "INSERT INTO `cust`(`fname`, `uname`, `email`, 
`color1`, `color2`, `color3`, `color4`, `colo5`) VALUES 
('$fname','$uname','$email','$pass1', '$pass2', '$pass3', '$pass4', 
'$pass5')";
   try{
       $register_result = mysqli_query($conn,$register_query);
       if($register_result){
           if(mysqli_affected_rows($conn)>0){
               header("location: success.html");
           }else{
               echo("error in registeration");
           }


       }

    }catch(Exception $ex){
       echo("error" .$ex->getMessage());
    }
 }else {

 }
   this is my code for handling the register.
  • 写回答

1条回答 默认 最新

  • doumubi6784 2017-10-29 15:48
    关注

    You will need to do a query before the INSERT query.

    $check_query = "SELECT COUNT(*) AS `total` FROM `cust` WHERE `color1`='$pass1' AND `color2`='$pass2' AND `color3`='$pass3' AND `color4`='$pass4' AND `color5`='$pass5'";
    if ($check_res = mysqli_query($conn, $check_query)) {
        $row = mysql_fetch_assoc($check_res);
        if ($row['total'] > 0) {
            // this means you shouldn't do the insert as a customer exists with this exact sequence of colours.
        }
        else {
            // do your insert here.
        }
    }
    

    If the value of total is > 0, then you know there is a customer with those exact colour combinations. This assumes a specific order of colours.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app