[英]Insert query for mysqli seems to not be working and I can't figure out why
For a project on school I have to create a site for a company.对于学校项目,我必须为公司创建一个站点。 I was working on the register system when I stumbled upon this problem.当我偶然发现这个问题时,我正在研究注册系统。 For some reason my query won't work on my databse.出于某种原因,我的查询不适用于我的数据库。 I've tried inputting the query in phpmyadmin, which worked fine, but if i want to use the query in php, it doesn't work.我试过在 phpmyadmin 中输入查询,效果很好,但如果我想在 php 中使用查询,它不起作用。 The database I'm using was premade, and it isn't auto incremented so I have to add all the values of all the rows when I want to insert new data.我使用的数据库是预制的,它不是自动递增的,所以当我想插入新数据时,我必须添加所有行的所有值。
This is the connection to my database I am using I use the header messages to indicate if the signup was succesfull:这是到我正在使用的数据库的连接我使用标题消息来指示注册是否成功:
function dbConnectionRoot () {
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "wideworldimporters";
$connection = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
return $connection;
}
And this is the insert script I'm using:这是我正在使用的插入脚本:
$sql = "INSERT INTO customers (
CustomerID, CustomerName, CustomerCategoryID,
PhoneNumber, FaxNumber, EmailAddress,
HashedPassword, BillToCustomerID, BuyingGroupID,
PrimaryContactPersonId, AlternateContactPersonID, DeliveryMethodID,
DeliveryCityID, PostalCityId, AccountOpenedDate,
StandardDiscountPercentage, IsStatementSent, IsOnCreditHold,
PaymentDays, WebsiteURL, DeliveryAddressLine1,
DeliveryPostalCode, PostalAddressLine1, PostalPostalCode,
LastEditedBy, ValidFrom, ValidTo)
VALUE (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
$statement = dbConnectionRoot()->prepare($sql);
mysqli_stmt_init(dbConnectionRoot());
if (dbConnectionRoot()->connect_errno) {
header("Location: signup:php?error=connection");
exit();
} elseif(!dbConnectionRoot()->query($sql)) {
header("Location: signup.php?error=queryerror");
exit();
} else {
//First we has the password. This is because if a hacker were to hack into the database, it could only see the hashed passwords.
// We use this hashing method(bcrypt) because it is always updated when there is a security breach.
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$maxCustomerID++;
//Again, we are making a prepared statement for security. This time we use 27 s'es because we want 27 different variables
$statement->bind_param("sssssssssssssssssssssssssss",
$maxCustomerID, $fullName, $customerCategory, $phoneNumber, $faxNumber, $email, $hashedPassword, $billToCustomerID,
$buyingGroupID, $primaryContactPersonId, $alternateContactPersonID, $deliveryMethodID, $deliveryCityID, $postalCityId, $accountOpenedDate,
$standardDiscountPercentage, $isStatementsent, $isOnCreditHold, $paymentDays, $websiteURL, $deliveryAddressLine1, $deliveryPostalCode,
$postalAddressLine1, $postalPostalCode, $lastEditedBy, $validFrom, $validTo);
$statement->execute();
return($statement);
//A message that the signup was succesfull
header("Location: signup.php?signup=success");
exit();
And this is the register form snippet这是注册表单片段
<form action="signupfunctions.php" method="post">
<label>Volledige naam: </label><input type="text" name="FullName"><br>
<label>E-mail adres: </label><input type="text" name="EmailAddress"><br>
<label>Wachtwoord: </label><input type="password" name="Password"><br>
<label>Herhaal uw wachtwoord: </label><input type="password" name="PasswordRepeat"><br>
<label>Telefoon nummer: </label><input type="text" name="PhoneNumber"><br>
<label>Fax nummer: </label><input type="text" name="FaxNumber"><br>
<button type="submit" name="signupbutton" >Registreer</button>
</form>
You have a syntax error in your SQL statement.您的 SQL 语句中有语法错误。 It should be: INSERT INTO ... VALUES
, not VALUE
.它应该是: INSERT INTO ... VALUES
,而不是VALUE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.