我正在建立一个音乐电子商务网站,出售一些音频。我已经建立了一个注册表格,有5个文本框,分别是姓名、电子邮件、密码、用户名和电话号码。我正在将此数据保存在wp注册表中。
我如何将此注册表格与网站链接,以便如果用户注册,那么只有他才能看到所有音乐内容,否则只能看到普通文本。
这是注册代码。
<?php
/* Template Name: Sign Up */
get_header();
$fNameErr = $familyNameErr = $phoneErr = $emailErr = $passwordErr = "";
$error_css = $fName = $familyName = $phone = $email = $password = "";
if (isset($_POST[\'submit\'])) {
if (empty($_POST["fName"])) {
$fNameErr = \'background-color:#ff4338\';
} else {
$fName = test_input($_POST["fName"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/", $fName)) {
$fNameErr = "*";
}
}
if (empty($_POST["familyName"])) {
$error_css = \'background-color:#ff4338\';
} else {
$familyName = test_input($_POST["familyName"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/", $familyName)) {
$familyNameErr = "*";
}
}
if (empty($_POST["email"])) {
$error_css = \'background-color:#ff4338\';
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["phone"])) {
$error_css = \'background-color:#ff4338\';
} else {
$phone = test_input($_POST["phone"]);
// check if e-mail address is well-formed
if (!preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $phone)) {
$phoneErr = "*";
}
}
if (empty($_POST["password"])) {
$error_css = \'background-color:#ff4338\';
} else {
$password = test_input($_POST["password"]);
// check if e-mail address is well-formed
}
global $wpdb;
$wpdb->insert(\'wp_registration\', array(
\'First_Name\' => $_POST[\'fName\'],
\'Last_Name\' => $_POST[\'familyName\'],
\'Phone\' => $_POST[\'phone\'],
\'Email\' => $_POST[\'email\'],
\'Password\' => $_POST[\'password\']
), array(
\'%s\',
\'%s\'
));
}
?>
<form action="index.php" class="modal-content animate" method="post">
<div class="container">
<input id="fName" name="fName" onblur="this.placeholder = \'Prénom nom\'" onfocus="this.placeholder=\'\'" placeholder="Prénom nom" required="" style="<?php echo $fNameErr; ?>" type="text">
<input name="familyName" onblur="this.placeholder = \'Nom de famille\'" onfocus="this.placeholder=\'\'" placeholder="Nom de famille" required="" style="<?php echo $error_css; ?>" type="text">
<input name="phone" onblur="this.placeholder = \'Numéro de téléphone\'" onfocus="this.placeholder=\'\'" placeholder="Numéro de téléphone" required="" style="<?php echo $error_css; ?>" type="number">
<input name="email" onblur="this.placeholder = \'Courriel\'" onfocus="this.placeholder=\'\'" placeholder="Courriel" required="" style="<?php echo $error_css; ?>" type="text">
<input name="password" onblur="this.placeholder = \'Mot de passe\'" onfocus="this.placeholder=\'\'" placeholder="Mot de passe" required="" style="<?php echo $error_css; ?>" type="password"><br>
<div class="buttons">
<input class="btn btn-primary custom-button red-btn" name="submit" type="submit" value="Inscription">
</div>
</div>
</form>