数据未使用php插入数据库[关闭]

问题描述 投票:-2回答:1

我有两种注册表单。一种是旧的,一种是新的。旧表单可以正常工作,但是新创建的表单没有将数据插入数据库并且没有错误。并且在我将页面重定向到登录页面之后,也有数据插入了php文件。 。因此,在我单击“提交”按钮后,新创建的表单也重定向到登录页面,但未将数据插入数据库。

这是表格

<form method="post" action="reguser.php">
                        <div class="row row-space">
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Full name</label>
                                    <input class="input--style-4" type="text" name="name">
                                </div>
                            </div>
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">NIC</label>
                                    <input class="input--style-4" type="text" name="nic">
                                </div>
                            </div>
                        </div>
                        <div class="row row-space">
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Date of Birth</label>
                                    <div class="input-group-icon">
                                        <input class="input--style-4 js-datepicker" type="text" name="dob">
                                        <i class="zmdi zmdi-calendar-note input-icon js-btn-calendar"></i>
                                    </div>
                                </div>
                            </div>
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Gender</label>
                                    <div class="p-t-10">
                                        <label class="radio-container m-r-45">Male
                                            <input type="radio" checked="checked" name="gender">
                                            <span class="checkmark"></span>
                                        </label>
                                        <label class="radio-container">Female
                                            <input type="radio" name="gender">
                                            <span class="checkmark"></span>
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row row-space">
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Email</label>
                                    <input class="input--style-4" type="email" name="email">
                                </div>
                            </div>
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Phone Number</label>
                                    <input class="input--style-4" type="text" name="mnum">
                                </div>
                            </div>
                        </div>
                        <div class="row row-space">
                            <div class="col">
                                <div class="input-group">
                                    <label class="label">Address</label>
                                    <input class="input--style-4" type="text" name="address">
                                </div>
                            </div>
                        </div>
                        <div class="row row-space">
                            <div class="col">
                                <div class="input-group">
                                    <label class="label">Password</label>
                                    <input class="input--style-4" type="password" name="pass">
                                </div>
                            </div>
                        </div>
                        <div class="p-t-15">
                            <button name="submit" class="btn btn--radius-2 btn--blue" type="submit">Submit</button>
                        </div>
                    </form>

这是数据插入php文件

<?php
include_once("dbConn.php");

if (isset($_POST['submit'])) {
    if (isset($_POST['name'], $_POST['nic'], $_POST['mnum'], $_POST['dob'],
    $_POST['address'], $_POST['email'], $_POST['pass'])) {

        $name = $_POST['name'];
        $nic = $_POST['nic'];
        $mnum = $_POST['mnum'];
        $dob = $_POST['dob'];
        $address = $_POST['address'];
        $email = $_POST['email'];
        $pass = $_POST['pass'];

        if (
            !$name == " " || !$nic == " " || !$mnum == " " || !$dob == " " || !$address == " "
            || !$email == " " || !$pass == " "
        ) {
            echo ('All the fileds are requered.');
        } else {
            if (!checkEmail($email, $conn)) {
                $query = "insert into patient (nic,name,dob,address,mobile,email,regNo,gender,pass) values(?,?,?,?,?,?,?,?,?);";
                $stmt = mysqli_stmt_init($conn);
                if (!mysqli_stmt_prepare($stmt, $query)) {
                    echo "Something went wrong while executing ";
                    exit();
                } else {
                    $query0 = "select id from patient;";
                    $out = mysqli_query($conn, $query0);
                    $result = mysqli_num_rows($out) + 1;
                    $regNo = "PTN$result";
                    $gender = "gender";
                    mysqli_stmt_bind_param($stmt, "ssssissss", $nic, $name, $dob, $address, $mnum, $email, $regNo, $gender, $pass);
                    mysqli_stmt_execute($stmt);
                    header("Location:login.php");
                }
            } else {
                echo "Email Exist";
                exit();
            }
        }
    }
} else {
    header("Location:patientRegistration.php?signup=failed");
    exit();
}



function checkEmail($email, $conn)
{
    $eqery = "select email from patient where email='$email';";
    $out = mysqli_query($conn, $eqery);
    $result = mysqli_num_rows($out);

    if ($result > 0) {
        return true;
    } else {
        return false;
    }
}



数据库连接php文件

<?php

$serverName = "localhost";
$userName = "root";
$password = "password";
$dbName = "easymedi";

$conn = mysqli_connect($serverName, $userName, $password, $dbName);


php mysql mysqli boolean-logic
1个回答
-4
投票

© www.soinside.com 2019 - 2024. All rights reserved.