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. 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>