I'm unable to insert a record here. Not sure why. My login works. My two echo
statements work. But no record gets recorded. All the variables that begin with 'type' or 'subj' are checkbox form elements, so I set those columns to 'Null' in the db (using phpMyAdmin). Not sure if that's correct - the idea is they're not required. Also, the first column in my db is not an entry from this form, it's supposed to be an id for the entry, set as primary key, not-null, and set to auto-increment. This is my first time doing this. How can I test what's happening? Thank you! - and what the heck happened to my codeblock!!!
<!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>