我想將數據添加到2個表中。數據到達我的表,稱爲沒有問題的公司。但是數據不會到達用戶表中。我沒有收到錯誤消息,之後頁面會加載管理頁面。將數據添加到2個表
<!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>
這是我的腳本文件
<?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');
?>
我的分貝值是在這一刻表中沒有被添加
userid, accountno, loginname, password, countteamname, status, counttype, piid, datecreated
counttype和PIID。 userid是一個由mysql自動遞增的數字。
一旦我得到這個上傳,我將致力於使用哈希來保護密碼。
我一直試圖弄清楚我自己幾個小時。我希望你能幫忙。
我沒有看到'countteamname' - >'$ _POST ['countteamname']''的輸入。我看到一個'name =「counttypename」'。這是一樣的嗎?你的插入失敗,因爲'countteamname'的'null'值'''_ _POST ['countteamname']' – Sean
@Sean謝謝Sean,這是問題所在。現在它正在添加到數據庫。 – Raggs