This is the table that is not writing all data to, but which should have the data inserted:
members_posts
`screenname` varchar(255) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`images_id` int(11) DEFAULT NULL,
`item` varchar(25) DEFAULT NULL,
`noi` varchar(124) DEFAULT NULL,
`notes` varchar(255) DEFAULT NULL,
`posted` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `screenname_idx` (`screenname`),
CONSTRAINT `screenname_posts` FOREIGN KEY (`screenname`) REFERENCES `members` (`screenname`) ON DELETE NO ACTION ON UPDATE NO ACTION)
When I attempt to open my postitem.php page, it loads the page, but already inserts the ID, NOTES, and POSTED fields - before entering any data into the form.
Here is the postitem.php form:
<?php
// Connection data to the database
require("/config/common.php");
// Check to see whether the screen name is already in use.
$query = "SELECT 1 FROM members WHERE screenname = :screenname";
$query_params = array(
':screenname' => $_POST['screenname']);
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$row = $stmt->fetch();
if($row)
{
die("This screen name is already in use");
}
$query = "INSERT INTO members_posts (screenname, item, noi, notes)
VALUES (:screenname, :item, :noi, :notes)";
$query_params = array(
':screenname' => $_POST['screenname'], ':item' => $_POST[$item], ':noi' => $_POST[$noi], ':notes' => $_POST['notes']);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
// Redirects the member back to the member's account page after posting an item.
//header("Location: myacct.php");
//die("Redirecting to myacct.php");
?>
<br />
<br />
<table align="center">
<th><h1>Post Item</h1></th>
<form enctype="multipart/form-data" action="postitem.php" method="post">
<tr><td>Screen Name:</td><td><b><?php echo htmlentities($_SESSION['user'] ['screenname'], ENT_QUOTES, 'UTF-8'); ?></b></td></tr>
<tr><td>Item:</td><td><select name="item">
<option VALUE='opt1'>Option 1</option>
<option VALUE='opt2'>Option 2</option>
<option VALUE='opt3'>Option 3/Computer</option>
</select></td></tr>
<tr><td>Name of item:</td><td><input type="text" name="noi" value="" /></td></tr>
<tr><td>Notes:</td><td><input type="text" name="notes" value="" /></td></tr>
<tr><td><input type="submit" src="/images/postit.png" value="Upload It" /></td></tr>
</form>
</table>
</body>
</html>
Thank you in advance for any help anyone could offer me!
PS: I did make the redirection to the myacct.php only a remark for testing, to keep the postitem page open for troubleshooting reasons.
name="submit_form"to your submit button? If not, you need to. You should update the code in your question with the current code that you are using.