我无法在此处插入记录。不知道为什么。我的登录有效。我的两个echo
陈述有效。但是没有记录被记录。所有以“type”或“subj”开头的变量都是复选框表单元素,因此我在数据库中将这些列设置为“Null”(使用 phpMyAdmin)。不确定这是否正确 - 想法是它们不是必需的。此外,我的数据库中的第一列不是此表单中的条目,它应该是条目的 id,设置为主键,不为空,并设置为自动增量。这是我第一次这样做。我怎样才能测试发生了什么?谢谢!-我的代码块到底发生了什么!!!
<!DOCTYPE html>
<head>
<title>Submit entry to database </title>
</head>
<body> <?php
//when Submit clicked
if ( isset($_POST['submit']) ){
$data_source = 'mysql:host=myHost;dbname=myDatabase';
$db_user = 'myUserName';
$db_password = 'myPassword';
$db = new PDO($data_source, $db_user, $db_password);
//load the form data into variables
$reviewer = $_POST['reviewer'];
$osj = $_POST['osj'];
$touchDate = $_POST['touchDate'];
$typeAction = $_POST['typeAction'];
$typeTech = $_POST['typeTech'];
$typeReg = $_POST['typeReg'];
$subjSuit = $_POST['subjSuit'];
$subjMFtran = $_POST['subjMFtran'];
$subjConcen = $_POST['subjConcen'];
$subjOption = $_POST['subjOption'];
$subjTrade = $_POST['subjTrade'];
$subjMuni = $_POST['subjMuni'];
$subjUIT = $_POST['subjUIT'];
$subjBkRecMFdir = $_POST['subjBkRecMFdir'];
$subjOBA = $_POST['subjOBA'];
$subjOther = $_POST['subjOther'];
$flavor = $_POST['flavor'];
$notes = $_POST['notes'];
echo $reviewer;
//prepare SQL statement
$statement = "INSERT INTO tblBranchTouches
(reviewer, osj, touchDate, typeAction, typeTech, typeReg, subjSuit,
subjMFtran, subjConcen, subjOption, subjTrade, subjMuni, subjUIT, subjBkRecMFdir,
subjOBA, subjOther, flavor, notes)
VALUES ('$reviewer', '$osj', '$touchDate', '$typeAction', '$typeTech', '$typeReg', '$subjSuit',
'$subjMFtran', '$subjConcen', '$subjOption', '$subjTrade', '$subjMuni', '$subjUIT', '$subjBkRecMFdir',
'$subjOBA', '$subjOther', '$flavor', '$notes') ";
$db->query($statement);
//confirm
echo "<h1>Thank You</h1>";
}
?>
<form method="post">
<p>
<label>
Reviewer:
<input type="text" name="reviewer" list="ARTies">
<datalist id="ARTies">
<option value = "MWeber">
<option value = "JBurchill">
<option value = "DGlazer">
<option value = "EKiburz">
<option value = "CSupak">
<option value = "MVallery">
<option value = "CHo">
<option value = "HPatil">
<option value = "NVanDoorn">
</datalist>
</label>
<label>
OSJ:
<input type="text" name="osj" maxlength=3 size=3>
</label>
<input type="date" name="touchDate" value="<?php echo date('Y-m-d', strtotime(date('Y/m/d'))); ?>">
</p>
<fieldset>
<legend>Type: </legend>
<p><label><input type="checkbox" name="typeAction"> Action </label>
<label><input type="checkbox" name="typeTech"> Tech. </label>
<label><input type="checkbox" name="typeReg"> Reg.</label></p>
</fieldset>
<fieldset>
<legend>Subject: </legend>
<p>
<label><input type="checkbox" name="subjSuit"> Suitability </label>
<label><input type="checkbox" name="subjMFtrans"> MF Transactions </label>
<label><input type="checkbox" name="subjConcen"> Concentrations </label>
<label><input type="checkbox" name="subjOption"> Options </label>
<label><input type="checkbox" name="subjTrade"> Trade Review </label>
<label><input type="checkbox" name="subjMuni"> Munis </label>
<label><input type="checkbox" name="subjUIT"> UITs </label>
<label><input type="checkbox" name="subjBkRecMFdir"> Bks-Recs-MFDirect </label>
<label><input type="checkbox" name="subjOBA"> OBAs </label>
<label><input type="checkbox" name="subjOther"> Other </label>
</p>
</fieldset>
<p>
<label>
Flavor:
<input type="number" name="flavor" min=1 max=5 value=3>
</label>
<label>Notes: <textarea name="notes"></textarea></label>
</p>
<p>
<input type="submit" name="submit" value="ENTER">
</p>
</form>
</body>
</html>