2016-03-07 73 views
0

这是我第一次使用PHP验证和我的验证工作完美。 我如何设计验证方式,选择echo函数还是必须更改我的验证代码才能对其进行设计。我尝试过使用span并回显错误函数并将echo更改为错误函数,例如$ emailErr但不是运气,验证不起作用。有什么建议么?我如何样式PHP验证

HTML

  <!--     <div id="first">--> 
      <input type="email" id="email" name="email" placeholder="Email Address" value='' required><!--<span class="error"><!--<?php //echo $c_emailErr;   ?></span>--> 
      <br> 

      <figure> 
       <input class ="login-field" type="password" id="pass1" name="pass1" value="" placeholder="Password" maxlength="30" required><!--<span class="error"><1--<?php //echo $c_pass1Err;   ?></span>--> 
       <input class ="login-field" type="password" id="pass2" name="pass2" value="" placeholder=" Confirm password" maxlength="30" required><!--<span class="error"><!--<?php //echo $c_pass2Err;   ?></span>--> 
       <div id="messages"></div> 
      </figure> 
      <p class="remember_me"> 
      </p> 
      <input type="submit" name="submit" value="Register" id="submit_button" class="btn btn-default"> 
      <br> 
     </form> 

PHP

<?php 
     if (isset($_POST['submit'])) { 
      $reg_errors = array(); 
      $c_email = $_POST['email']; 
      $c_pass1 = $_POST['pass1']; 
      $c_pass2 = $_POST['pass2']; 
      $emailErr = $pass1Err = $pass2Err = ""; 
      // $c_email = $c_pass1 = $c_pass2 = ""; 
      // Remove all illegal characters from email 
      // $c_email = filter_var($c_email, FILTER_SANITIZE_EMAIL); 
      //Checking the email address 
      if (!filter_var($c_email, FILTER_VALIDATE_EMAIL) === false) { 
      echo("<b> This is a valid email address </b>"); 
      } else { 
       echo("<b> Email is not a valid email address</b>"); 
      } 
      if (strlen($c_pass1) <= '8') { 
      echo "<b>Your Password Must Contain At Least 8 Characters!</br>"; 
      //check passwords 
      }elseif ($c_pass1 == $c_pass2) { 
      $q = "INSERT INTO  Cus_Register(Cus_Email,Cus_Password,Cus_confirm_password) VALUES (?,?,?)"; 
       $stmt = mysqli_prepare($dbc, $q); 
       //new 
       // $stmt = mysqli_prepare($dbc, $insert_c); 
       //debugging 
       //$stmt = mysqli_prepare($dbc, $insert_c) or die(mysqli_error($dbc)); 

       mysqli_stmt_bind_param($stmt, 'sss', $c_email, $c_pass1, $c_pass2); 
       if ($q) { 
        echo "<script> alert('registration sucessful')</script>"; 
       } 
      } else { 
       echo "<b>Oops! Your passwords do not </b>"; 
      } 
     } 

     ?> 
+1

,PHP是服务器侧。 – 2016-03-07 02:53:51

+0

您可以像使用HTML和CSS一样显示浏览器中显示的任何其他数据,从而对错误消息进行样式设置。尽管如此,你应该将它与服务器端代码分开。 – purpleninja

回答

1

说你有文字标记,你的代码

<? 
 
echo '<t>this is some text'; 
 
?>

添加样式所有你只需要做的是在CSS样式的“T”的标签,像这样

t{ 
 
    font-size:3px; 
 
    background-color:red; 
 
    // other styles 
 
    }

您使用的回声添加什么都样式代码是适当
+0

哦有道理。谢谢! – jerneva

+0

非常欢迎:) – 2016-03-07 03:10:31