Howdy! I know I’m missing something rather simple here but I just can’t seem to find it. I need another set of eyes. The data is being passed from the form to the php page that captures the data into variables. I can echo out the variables with the data but my query will not update the data table, even though my code indicates that the database was updated.
Here’s the form.
<fieldset>
<legend>Enter New Term</legend>
<form name ="input" action="insert.php" method="post">
<label for="newterm" class="label">New Term</label>
<input type="text" name="newterm" id="newterm" value=""/>
<label for="definition" class="label">Definition 1</label>
<input type="text" name="definition1" id="definition1" value=""/>
<label for="definition2" class="label">Definition 2</label>
<input type="text" name="definition2" id="definition2" value=""/>
<label for="reference1" class="label">Reference Key 1</label>
<input type="text" name="reference1" id="reference1" value=""/>
<label for="reference2" class="label">Reference 2</label>
<input type="text" name="reference2" id="reference2" value=""/>
<label for="ilink1" class="label">Reference Link 1</label>
<input type="text" name="ilink1" id="ilink1" value=""/>
<label for="ilink2" class="label">Reference Link 2</label>
<input type="text" name="ilink2" id="ilink2" value=""/>
<label for="comment" class="label">Comment</label>
<input type="text" name="comment" id="comment" value=""/>
<input type="submit" name="submit" id="submit" value="Add Term" />
</form>
</fieldset>
Here’s the update file that captures the form data and sends to the database.
include 'conn.php';
$new_term = $_POST['newterm'];
$def1 = $_POST['definition1'];
$def2 = $_POST['definition2'];
$ref1 = $_POST['reference1'];
$ref2 = $_POST['reference2'];
$link1 = $_POST['ilink1'];
$link2 = $_POST['ilink2'];
$cmmnt = $_POST['comment'];
echo $new_term;
echo $def1;
echo $def2;
echo $ref1;
echo $ref2;
echo $link1;
echo $link2;
echo $cmmnt;
$query = "INSERT INTO terms (id, keyword, def1, def2, kref1, kref2, iref1, iref2, comment, entrydate)
values(".$new_term."','".$def1."','".$def2."','".$ref1."','".$ref2."','".$link1."','".$link2."','".$cmmnt."')";
if(!$query) {
die('This data is not valid and will not be saved.');
}
echo 'Your data has been validated and has been committed to the database';
Here is the structure of the table
CREATE TABLE terms(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
keyword VARCHAR(35)NOT NULL UNIQUE,
def1 VARCHAR(255) NOT NULL,
def2 VARCHAR(255) NULL,
kref1 VARCHAR(55) NULL,
kref2 VARCHAR(55) NULL,
iref1 VARCHAR(255) NULL,
iref2 VARCHAR(255) NULL,
comment VARCHAR(255) NULL,
entrydate DATETIME
)Engine = InnoDB DEFAULT CHARSET=utf8
Thanks in advance.