我想将数据添加到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