gpt4 book ai didi

php - 一个数据库中有两个表,但只有一个在工作

转载 作者:行者123 更新时间:2023-11-30 21:51:35 24 4
gpt4 key购买 nike

<分区>

我在数据库中创建了两个表,一个用于客户的登录和注册,另一个用于经销商的登录和注册。只有客户表在工作。但是在经销商的情况下,数据不会保存到表格中。这是数据库代码

   <?php
session_start();

// variable declaration
$username = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";


$db = mysqli_connect('localhost', 'root', '', 'registration');

// SIGNUP CUSTOMER
if (isset($_POST['reg_user'])) {

$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$telephone = mysqli_real_escape_string($db,$_POST['telephone']);
$country = mysqli_real_escape_string($db,$_POST['country']);
$state= mysqli_real_escape_string($db,$_POST['state']);


if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if (empty($telephone)) { array_push($errors, "Telephone no. is required"); }
if (empty($country)) { array_push($errors, "country is required"); }
if (empty($state)) { array_push($errors, "state is required"); }

if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}


if (count($errors) == 0) {
$password = md5($password_1);
$query = "INSERT INTO users (username, email, password, telephone,country,state)
VALUES('$username', '$email', '$password','$telephone','$country','$state')";
mysqli_query($db, $query);

$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index1.php');
}

}
// ...

// SIGNIN CUSTOMER
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}

if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index1.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
//SIGN UP DEALER
if (isset($_POST['reg_dealer'])) {

$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$account = mysqli_real_escape_string($db, $_POST['account']);
$IFSC = mysqli_real_escape_string($db,$_POST['IFSC']);
$target = mysqli_real_escape_string($db,$_POST['target']);
$sales= mysqli_real_escape_string($db,$_POST['sales']);
$date= mysqli_real_escape_string($db,$_POST['date']);
$address= mysqli_real_escape_string($db,$_POST['address']);
$telephone = mysqli_real_escape_string($db,$_POST['telephone']);
$country = mysqli_real_escape_string($db,$_POST['country']);
$state= mysqli_real_escape_string($db,$_POST['state']);



if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if (empty($telephone)) { array_push($errors, "Telephone no. is required"); }
if (empty($country)) { array_push($errors, "country is required"); }
if (empty($state)) { array_push($errors, "state is required"); }
if (empty($account)) { array_push($errors, "account is required"); }

if (empty($IFSC)) { array_push($errors, "IFSC is required"); }

if (empty($sales)) { array_push($errors, "sales is required"); }

if (empty($date)) { array_push($errors, "date is required"); }

if (empty($target)) { array_push($errors, "target is required"); }

if (empty($address)) { array_push($errors, "address is required"); }


if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}


if (count($errors) == 0) {
$password = md5($password_1);
$query = "INSERT INTO dealers (username, email, password, account,IFSC,target,sales, date,address,telephone,country,state)
VALUES('$username', '$email', '$password','$account','$IFSC','$target','$sales','$date','$address',$telephone','$country','$state')";
mysqli_query($db, $query);

$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index1.php');
}

}
//SIGNIN DEALER
if (isset($_POST['login_dealer'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}

if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM dealers WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index1.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}


?>

reg_user 是用于注册客户的按钮名称login_user 是用于登录客户的按钮的名称reg_dealer 是用于注册经销商的按钮的名称login_dealer 是用于登录经销商的按钮的名称

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com