这是我的register.php
页,错误在echo $row['firstname'];
和echo $row['lastname'];
行中,但其他人正常工作
<form action="code.php" method="POST">
<div class="modal-body">
<div class="form-group">
<label> Username </label>
<input type="text" name="username" class="form-control" placeholder="Enter Username">
</div>
<div class="form-group">
<label> firstname </label>
<input type="text" name="firstname" class="form-control" placeholder="Enter firstname">
</div>
<div class="form-group">
<label> lastname </label>
<input type="text" name="lastname" class="form-control" placeholder="Enter lastname">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" placeholder="Enter Email">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Enter Password">
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password" name="confirmpassword" class="form-control" placeholder="Confirm Password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" name="registerbtn" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>
<div class="container-fluid">
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Admin Profile
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addadminprofile">
Add Admin Profile
</button>
</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<?php
$connection = mysqli_connect("localhost","root","","opmmusic");
$query = "SELECT * FROM users";
$query_run = mysqli_query($connection,$query)
?>
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th> ID </th>
<th> Username </th>
<th> Firstname </th>
<th> lastname </th>
<th> Email </th>
<th> Password</th>
<th> EDIT </th>
<th> DELETE </th>
</tr>
</thead>
<tbody>
<?php
if(mysqli_num_rows($query_run)> 0)
{
while($row = mysqli_fetch_assoc($query_run))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['password']; ?></td>
<td>
<form action="" method="post">
<input type="hidden" name="edit_id" value="">
<button type="submit" name="edit_btn" class="btn btn-success"> EDIT</button>
</form>
</td>
<td>
<form action="" method="post">
<input type="hidden" name="delete_id" value="">
<button type="submit" name="delete_btn" class="btn btn-danger"> DELETE</button>
</form>
</td>
</tr>
<?php
}
}
else {
echo "No Record found";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
我的code.php
<?php
session_start();
$connection = mysqli_connect("localhost","root","","opmmusic");
if(isset($_POST['registerbtn']))
{
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirm_password = $_POST['confirmpassword'];
if($password === $confirm_password)
{
$query = "INSERT INTO users (username,firstname,lastname,email,password) VALUES ('$username','$firstname','$lastname','$email','$password')";
$query_run = mysqli_query($connection, $query);
if($query_run)
{
echo "done";
$_SESSION['success'] = "Admin is Added Successfully";
header('Location: register.php');
}
else
{
echo "not done";
$_SESSION['status'] = "Admin is Not Added";
header('Location: register.php');
}
}
else
{
echo "pass no match";
$_SESSION['status'] = "Password and Confirm Password Does not Match";
header('Location: register.php');
}
}
?>
答案 0 :(得分:-1)
我在您的表单上没有看到任何错误。
可能是表单请求尚未设置或定义。
尝试一下。
if (isset($_POST['registerbtn']))
{
(isset($_POST['username']) ? $username = $_POST['username'] : $username = '';
(isset($_POST['firstname']) ? $firstname = $_POST['firstname'] : $firstname = '';
(isset($_POST['lastname']) ? $lastname = $_POST['lastname'] : $lastname = '';
(isset($_POST['email']) ? $email = $_POST['email'] : $email = '';
(isset($_POST['password']) ? $password= $_POST['password'] : $password = '';
(isset($_POST['confirmpassword']) ? $confirmpassword = $_POST['confirmpassword']
: $confirmpassword = '';
//some codes here...
}