Hello people, I'm new here
I've been following a guide in order to build a form for submitting basic content to a MySQL table.
The code I've used for the forms goes like this
<?php
// Check if form submitted
if (isset($_POST['submitted'])) {
require_once
('Connections/AberDigs.php'); // Connect to DB
$errors = array(); //Error array.
// Check for a title:
if (empty($_POST['Title'])) {
$errors[] = 'You forgot to enter your
title.';
} else {
$title = mysqli_real_escape_string
($AberDigs, trim (stripslashes
($_POST['Title'])));
}
// Check for content
if (empty($_POST['Content'])) {
$errors[] = 'You forgot to enter your
content.';
} else {
$cont = mysqli_real_escape_string
($AberDigs, trim (stripslashes
($_POST['Title'])));
}
// Check for an author
if (empty($_POST['Author']));
$errors[] = 'You forgot to assign an
author for the post.';
} else {
$atr = mysqli_real_escape_string
($AberDigs, trim (stripslashes
($_POST['Author'])));
}
if (empty($errors)) { // If all is OK
//Input into database
//Query
$q = "INSERT INTO NewsFeed (Title, Date, Content,
Author) VALUES ('$title', CURDATE(), '$cont', '$atr' )";
$r = @mysqli_query ($AberDigs, $q); //Run Query
if ($r) { //if it ran OK.
//Confirmation message
echo '<h1>You have submitted this story</h1>';
} else { //If did not run OK
//Error message
echo '<h1>Failed to submit</h1>';
echo '<p>' . mysqli_error($AberDigs) .
'<br /><br />Query: ' . $q .
'</p>';
}
mysqli_close($AberDigs); //close DB connection
exit(); //Quit the script
} else { //report errors
echo '<h1>Error!</h1>
<p class="error>The following
error(s) occurred: <br />';
foreach ($errors as $msg) { // print each error
echo " - £msg<br />\n";
}
echo '</p><p>Please try
again. </p><p><br /></p>';
}
mysqli_close($AberDigs); //close DB connection
?>
<h1>News Edit</h1>
<p>Edit News</p>
<form action="newsedit.php" method="post">
<p>Title: <input type="text"
name="Title" size="15"
maxlength="25" value="<?php if
(isset($_POST['Title'])) echo
$_POST['Title']; ?>" /></p>
<p>Content:
<textarea name="Content" cols="40" rows="8"><?php if
(isset($_POST['Content'])) echo
$_POST['Content']; ?>
</textarea>
</p>
<p>Author: <input type="text"
name="Title" size="15"
maxlength="20" value="<?php if
(isset($_POST['Author'])) echo
$_POST['Author']; ?>" /></p>
<p><input type="submit" name="submit"
value="Register" /></p>
<input type="hidden" name="submitted"
value="TRUE" />
</form>
I've tried possible solutions from the book but I don't seem to be getting anywhere, my webpage simply displays this from the start:
Failed to submit
Query: INSERT INTO NewsFeed (Title, Date, Content, Author) VALUES ('', CURDATE(), '', '' )
If anyone can point me in the right direction I would appreciate it, thank you 🙂
Jason