2017-03-08 107 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的密碼和數據庫名稱