trouble在php数据库中插入值

ttcibm8c  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(248)

我有一个db(使用phpmyadmin)。我想在主表中输入数据,但问题是我想在两个不同的html页面中获取用户的详细信息。
如果我能够将数据从htmlpage1存储到db中,那么下一个html页面就不会存储任何数据。
我试过了;
1-在第二页中使用where命令。没有帮助。2-尝试将数据保存到变量中,并在从htmlpage2获得数据时将所有数据存储在一起。
注:
html页面1有一个提交按钮“注册”html页面2有一个提交按钮“提交”
这是密码。;

<?php
session_start();
$enrollment = "";
$username = "";
$email = "";
$password = "";
$fathername = "";
$dateofbirth = "";
$course = "";
$contact = "";
$gender = "";
$address = "";
$city = "";
$state = "";
$country = "";
$tenth = "";
$twth = "";
$ug = "";
$pg = "";
$phd = "";
$sem1 = "";
$sem2 = "";
$sem3 = "";
$sem4 = "";
$train1 = "";
$train2 = "";
$ts1 = "";
$ts2 = "";
$ts3 = "";
$errors = array();

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

if (isset($_POST['register'])){
        $enrollment = mysqli_real_escape_string($db, $_POST['enrollment']);
        $username = mysqli_real_escape_string($db, $_POST['sname']);
        $email = mysqli_real_escape_string($db, $_POST['email']);
        $password = mysqli_real_escape_string($db, $_POST['password']);
        $fathername = mysqli_real_escape_string($db, $_POST['fname']);
        $dateofbirth = mysqli_real_escape_string($db, $_POST['dob']);
        $course = mysqli_real_escape_string($db, $_POST['course']);
        $contact = mysqli_real_escape_string($db, $_POST['contact']);
        $gender = mysqli_real_escape_string($db, $_POST['gender']);
        $address = mysqli_real_escape_string($db, $_POST['address']);
        $city = mysqli_real_escape_string($db, $_POST['city']);
        $pin = mysqli_real_escape_string($db, $_POST['pincode']);
        $state = mysqli_real_escape_string($db, $_POST['state']);
        $country = mysqli_real_escape_string($db, $_POST['country']);

        if (empty($username)){
            array_push($errors, "Username is required");
        }
        if (empty($email)){
            array_push($errors, "Email is required");
        }
        if (empty($password)){
            array_push($errors, "Password is required");
        }
}
if (isset($_POST['submit'])){
        $tenth = mysqli_real_escape_string($db, $_POST['ClassX_Percentage']);
        $twth = mysqli_real_escape_string($db, $_POST['ClassXII_Percentage']);
        $ug = mysqli_real_escape_string($db, $_POST['Graduation_Percentage']);
        $pg = mysqli_real_escape_string($db, $_POST['Masters_Percentage']);
        $phd = mysqli_real_escape_string($db, $_POST['PhD_Percentage']);
        $sem1 = mysqli_real_escape_string($db, $_POST['topic1']);
        $sem2 = mysqli_real_escape_string($db, $_POST['topic2']);
        $sem3 = mysqli_real_escape_string($db, $_POST['topic3']);
        $sem4 = mysqli_real_escape_string($db, $_POST['topic4']);
        $train1 = mysqli_real_escape_string($db, $_POST['train1']);
        $train2 = mysqli_real_escape_string($db, $_POST['train2']);
        $ts1 = mysqli_real_escape_string($db, $_POST['sub']);
        $ts2 = mysqli_real_escape_string($db, $_POST['prog']);
        $ts3 = mysqli_real_escape_string($db, $_POST['cer']);

        if (empty($ts1)){
            array_push($errors, "ts is required");
        }
        if (empty($ts2)){
            array_push($errors, "ts is required");
        }
        if (empty($ts3)){
            array_push($errors, "ts is required");
        }   
        if (count($errors)==0){
            $password = md5($password);
            $sql="INSERT INTO studetails (enrollment, name, email, password, fname, dob, course, contact, gender, address, city, pin, state, country, tenth, twth, ug, pg, phd, sem1, sem2, sem3, sem4, train1, train2, ts1, ts2, ts3) VALUES ('$enrollment','$username', '$email', '$password','$fathername','$dateofbirth','$course','$contact','$gender','$address','$city','$pin','$state','$country','$tenth','$twth','$ug','$pg','$phd','$sem1','$sem2','$sem3','$sem4','$train1','$train1','$ts1','$ts2','$ts3')";
            mysqli_query($db, $sql);
            $_SESSION['sname'] = $username;
            $_SESSION['success'] = "You are now logged in";
            header('location: preview.php');
        }
}
?>

注:

$enrollment = "";
$username = "";
$email = "";
$password = "";
$fathername = "";
$dateofbirth = "";
$course = "";
$contact = "";
$gender = "";
$address = "";
$city = "";
$state = "";
$country = "";

这将从html第1页存储,其余的从html第2页存储
在这种情况下,db中的哪些值应该接受null??

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题