2017-03-08 93 views
-3

我想开发一个简单的HTML页面,3个文本字段HTML页面验证,包括PHP和MySQL

的UniqueID: 姓: 名字:

这3个领域是在MySQL数据库表列,所以当任何用户输入UniqueID,页面应该连接到数据库(使用php)检查UniqueID是否存在于数据库中,其余列需要填充在HTML页面中(这些检索值名字&姓氏不应该能够修改由用户),如果在数据库中不存在UniqueID,则用户应该有机会填写名字&姓氏,然后将值提交给数据库。

+1

你想从我们这里得到什么 - 写你所有的codez? –

+0

我想再开发一个谷歌有人可以帮我吗? –

+0

我应该向您发送报价吗? –

回答

0

你根本可以用这个做到这一点:

dbconnect.php

<?php 
//connect to mysql database 
$con = mysqli_connect("localhost", "root", "123456pass", "database") or die("Error " . mysqli_error($con)); 
?> 

的index.php

<?php 
    include_once 'dbconnect.php'; 

    //set validation error flag as false 
    $error = false; 

    //check if form is submitted 
    if (isset($_POST['register'])) { 
     $uniqueid = mysqli_real_escape_string($con, $_POST['uniqueid']); 
     $firstn = mysqli_real_escape_string($con, $_POST['firstn']); 
     $lastn = mysqli_real_escape_string($con, $_POST['lastn']); 

     //name can contain only alpha characters and space 
     if (!preg_match("/^[a-zA-Z ]+$/", $firstn . " " . $lastn)) { 
      $error = true; 
      $name_error = "Name must contain only alphabets and space"; 
     } 
     if (empty(mysqli_query($con, "SELECT * FROM users WHERE UniqueID='" . $uniqueid . "'"))) { 
     $error = true; 
     $uniqueid_error = "The UniqueID " . $uniqueid . " already exists!"; 
     } 

     if (!$error) { 
      if(mysqli_query($con, "INSERT INTO users(UniqueID,FirstName,LastName) VALUES('" . $uniqueid . "', '" . $firstn . "', '" . $lastn . "')")) { 
       $successmsg = "Successfully Registered!"; 
      } else { 
       $errormsg = "Error in registering...Please try again later!"; 
      } 
     } 
    } 
    ?> 
    <html> 
    <body> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-4 col-md-offset-4 well"> 
       <form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="registerform"> 
        <fieldset> 
         <legend>Register</legend> 
         <div class="form-group"> 
          <label for="name">Unique ID</label> 
          <input type="text" name="uniqueid" placeholder="Enter The UniqueID" required value="<?php if($error) echo $uniqueid; ?>" class="form-control" /> 
          <span class="text-danger"><?php if (isset($uniqueid_error)) echo $uniqueid_error; ?></span> 
         </div> 

         <div class="form-group"> 
          <label for="name">First Name</label> 
          <input type="text" name="firstn" placeholder="First Name" required value="<?php if($error) echo $firstn; ?>" class="form-control" />Sign Up 
         </div> 

         <div class="form-group"> 
          <label for="name">Last Name</label> 
          <input type="text" name="lastn" placeholder="Last Name" required class="form-control" /> 
          <span class="text-danger"><?php if (isset($name_error)) echo $name_error; ?></span> 
         </div> 

         <div class="form-group"> 
          <input type="submit" name="register" value="Register" class="btn btn-primary" /> 
         </div> 
        </fieldset> 
       </form> 
       <span class="text-success"><?php if (isset($successmsg)) { echo $successmsg; } ?></span> 
       <span class="text-danger"><?php if (isset($errormsg)) { echo $errormsg; } ?></span> 
      </div> 
     </div> 
    </div> 
    </body> 
    </html> 

的index.php与替换users(UniqueID,FirstName,LastName)表名和c列名称。在dbconnect.php替换"123456pass", "database"用mysql的密码和数据库名称