你根本可以用這個做到這一點:
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的密碼和數據庫名稱
你想從我們這裏得到什麼 - 寫你所有的codez? –
我想再開發一個谷歌有人可以幫我嗎? –
我應該向您發送報價嗎? –