我正在运行以下查询以注册新用户。但是,只有用户名,密码和电子邮件地址字段才会插入到数据库中。 我已经检查过,拼写与我在数据库中的拼写完全一致。 不知道问题出在哪里。 我已经注释掉了一些代码以便找出问题。这是完整的代码:
<?php
/* Main page with two forms: sign up and log in */
require 'db_connection.php';
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Sign-Up Form: <?php include 'css/css.html'; ?></title>
</head>
<?php
/* form.php */
//session_start();
$_SESSION['message'] = '<div class="alert alert-error"><?= $_SESSION[\'message\'] ?></div>';
$mysqli = new mysqli('localhost', 'root', '', 'customer.accounts');
/*if (isset($_POST['btn-submit']))
$first_name = ($_POST['first_name']);
$last_name = ($_POST['last_name']);
$username = ($_POST['username']);
$DeliveryAddress= ($_POST['DeliveryAddress']);
$CreditCardNo= ($_POST['CreditCardNo']); */
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//check if two passwords match
// if ($_POST['password'] == $_POST['password']) {
//define other variables with submitted values from $_POST,
$username = $mysqli->real_escape_string($_POST['username']);
$email = $mysqli->real_escape_string($_POST['email']);
$first_name = $mysqli->real_escape_string($_POST['first_name']);
$last_name = $mysqli->real_escape_string($_POST['last_name']);
$password = $mysqli->real_escape_string($_POST['password']);
$DeliveryAddress = $mysqli->real_escape_string($_POST['DeliveryAddress']);
$CreditCardNo = $mysqli->real_escape_string($_POST['CreditCardNo']);
//md5 hash password for security
$password = md5($_POST['password']);
$_SESSION['username'] = $username;
if(!preg_match('/^[a-zA-Z ]*$/',$first_name)) //validate firstname
{
$nameErr="Name can only contain alphabets";
$execute=false;
}
if(!preg_match('/^[a-zA-Z ]*$/',$last_name)) //validate lastname
{
$nameErr="Name can only contain alphabets";
$execute=false;
}
if(!preg_match('/^[0-9]*$/',$ContactNo)) //validate phone
{
$phoneErr="Mobile Number can only contain digits";
$execute=false;
}
if(strlen($ContactNo)<10)
{
$phoneErr="<br/>Mobile number is too short";
$execute=false;
}
if(strlen($CreditCardNo)<16) //validate card details
{
$phoneErr="<br/>Credit Card Number is too short";
$execute=false;
}
if($execute!=false)
//Bind and insert user data into database
$sql = "INSERT INTO useraccounts (first_name,last_name,username, email, password,DeliveryAddress,CreditCardNo) VALUES (?,?,?,?,?,?,?)";
$stmt->bind_param('ssssssi', $first_name, $last_name, $username,$email,$password,$DeliveryAddress,$CreditCardNo);
$username= $_SESSION('username');
$stmt->execute();
//check if mysql query is successful, then register the user.
if ($stmt === true) {
$_SESSION['message'] = "Registration successful!"
. "Added $username to the database!";
//redirect the user to welcome.php if the registration is successful
header("location: welcome.php");
} else {
$_SESSION['message'] = 'User could not be added to the database!';
}
$mysqli->close();
//else {
// $_SESSION['message'] = 'Two passwords do not match!';
//if ($_SERVER["REQUEST_METHOD"] == "POST")
}
function test_input($data){
$data=trim($data);
$data=htmlspecialchars($data);
return $data;
}
//Registration Form
?>
<link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="form.css" type="text/css">
<div class="body-content">
<div class="module">
<h1>Create an Account </h1>
<form class="form" action="form.php" method="post" enctype="multipart/form-data" autocomplete="off">
<div class="alert alert-error"> <?= $_SESSION['message'] ?></div>
<input type="text" placeholder="First Name" name="first_name" required />
<input type="text" placeholder="Last Name" name="last_name" required />
<input type="text" placeholder="User Name" name="username" required />
<input type="email" placeholder="Email" name="email" required />
<input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
<input type="password" placeholder="Confirm Password" name="confirmpassword" autocomplete="new-password" required />
<input type="text" placeholder="Delivery Address" name="DeliveryAddress" autocomplete="DeliveryAddress" required />
<input type="text" placeholder="Payment Details" name="CreditCardNo" autocomplete="CreditCardNo" required />
<input type="submit" value="Register" name="submit" class="btn btn-block btn-primary" />
</form>
</div>
&#13;
答案 0 :(得分:-2)
Ivar,我相信你可能会通过使用绑定参数使情况复杂化。这为其他简单查询添加了间接级别。对于标准查询,我会使用参数标记,例如(添加调试):
I'm trying to get a simple log/email alert to fire in Marklogic and am following the examples in the documentation. However I cannot seem to execute an action.
My steps:
[1] create config and insert.
[2] create action and insert.
[3] create rule and insert.
导出的文件仅用于帮助查找原始问题的未设置参数的来源。如果它们在数组中设置,则也应通过查询设置它们。如果SQL无效,则它将在prepare调用中失败。如果参数列表不正确,它将在执行调用中失败。