I am trying to add data into 2 tables. the data arrives into my table called companies with no issues. however the data does not arrive into the table users. I do not get an error message and the page loads the admin page afterwards.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<title>Create a Company</title>
<link rel="stylesheet" type="text/css" href="/css.css"/>
</head>
<body>
<h2 class="header"> Create a Company </h2>
<form action="processcompany.php" method="post">
<input class="entry" placeholder="Account No" name="accountno" type="text"><br>
<input class="entry" placeholder="Company Name" name="companyname" type="text" required="required"><br>
<input class="entry" placeholder="GST/VAT/ABN/TAX No" name="taxno" type="text" required="required"><br>
<input class="entry" placeholder="Address Line 1" name="address1" type="text" value=""><br>
<input class="entry" placeholder="Address Line 2" name="address2" type="text" value=""><br>
<input class="entry" placeholder="Suburb/County" name="suburb" type="text" value=""><br>
<input class="entry" placeholder="State" name="state" type="text" value=""><br>
<input class="entry" placeholder="Post/Zip Code" name="postcode" type="text" value=""><br>
<input class="entry" placeholder="Country" name="country" type="text" value=""><br>
<input class="entry" placeholder="Primary Contact" name="primarycontact" type="text" value=""><br>
<input class="entry" placeholder="Primary Email" name="primaryemail" type="text" value=""><br>
<input class="entry" placeholder="Subscription Type" name="subscriptiontype" type="text" value=""><br>
<input class="entry" placeholder="Subscription Status" name="subscriptionstatus" type="hidden" value="Active"><br>
<input class="entry" placeholder="Subscription End Date" name="subscriptionenddate" type="text" value=""><br><br><br>
<input class="entry" placeholder="login Email Address" name="loginname" type="text" value=""><br>
<input class="entry" placeholder="First and Last Name" name="counttypename" type="text" value=""><br>
<input class="entry" placeholder="User Type" name="usertype" type="hidden" value="Company Administrator"><br>
<input class="entry" placeholder="User Status" name="status" type="hidden" value="Active"><br>
<input class="entry" placeholder="Password" name="password" type="text" value=""><br>
<input class="button" type="submit">
</form>
</body>
</html>
this is my script file
<?php
include 'db.php';
$sql = "INSERT INTO `companies`
( `accountno`, `companyname` ,
`taxno` , `address1`, `address2`, `suburb` ,
`state` , `postcode`, `country`, `primarycontact` ,
`primaryemail`, `subscriptiontype` ,
`subscriptionstatus`, `subscriptionenddate`,
`datecreated` )
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
$stmt = $conn->prepare($sql);
if ( ! $stmt ) {
echo $stmt->error;
exit;
}
$stmt->bind_param('isssssssssssss',
$_POST['accountno'],
$_POST['companyname'],
$_POST['taxno'],
$_POST['address1'],
$_POST['address2'],
$_POST['suburb'],
$_POST['state'],
$_POST['postcode'],
$_POST['country'],
$_POST['primarycontact'],
$_POST['primaryemail'],
$_POST['subscriptiontype'],
$_POST['subscriptionstatus'],
$_POST['subscriptionenddate']
);
$stmt->execute();
if ( ! $stmt ) {
echo $stmt->error;
exit;
}
$sqla = "INSERT INTO `users`
( `accountno`, `loginname` ,
`password` , `countteamname`, `status`, `usertype` ,
`datecreated` )
VALUES (?,?,?,?,?,?,NOW())";
$stmta = $conn->prepare($sqla);
if ( ! $stmta ) {
echo $stmta->error;
exit;
}
$stmta->bind_param('isssss',
$_POST['accountno'],
$_POST['loginname'],
$_POST['password'],
$_POST['countteamname'],
$_POST['status'],
$_POST['usertype']
);
$stmta->execute();
if ( ! $stmta ) {
echo $stmta->error;
exit;
}
mysqli_close($conn);
header('location: admin.php');
?>
my db values are
userid, accountno, loginname, password, countteamname, status, counttype, piid, datecreated
counttype and piid are not being added at this moment to the table. userid is an auto increment number by mysql.
once i get this uploaded, I will work on securing the password using hash.
I have been trying to figure this out on my own for hours. I hope you can help.
By the looks of it your only adding to the one table with the query
what about concatenating two queries
$sql = "QUERY;";
$sql .= "QUERY;";
use the .= to concatenate both queries.