Hi all,
I hope someone can help. I have a problem but can’t see what I’m doing wrong. A second opinion would be very useful. My code should post a title, text, intro and link… but the link text ends up in the entry text and the actual link gives a link to the page to edit the link info - I’ve got a bit lost and need some help.
Any would be much appreciated.
Code below.
Thank you for any help.
[php]
$page_title = ‘New Link’;
include (‘includes/header.html’);
// Check if the form has been submitted:
if (isset($_POST[‘submitted’])) {
require_once ('xxxx'); // Connect to the db.
$errors = array(); // Initialise an error array.
// Check for a title:
if (empty($_POST['title'])) {
$errors[] = 'You forgot to enter the link title.';
} else {
$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
}
// Check for an intro:
if (empty($_POST['intro'])) {
$errors[] = 'You forgot to enter the link intro.';
} else {
$intro = mysqli_real_escape_string($dbc, trim($_POST['intro']));
}
// Check for an entry:
if (empty($_POST['entry'])) {
$errors[] = 'You forgot to enter the link entry text.';
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST['entry']));
}
// Check for an link:
if (empty($_POST['link'])) {
$errors[] = 'You forgot to enter the link.';
} else {
$entry = mysqli_real_escape_string($dbc, trim($_POST['link']));
}
if (empty($errors)) { // If everything is ok.
// Register the user in the database...
// Make the query:
$q = "INSERT INTO links (title, intro, entry, link, creation_date) VALUES ('$title', '$intro', '$entry', '$link', NOW() )";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran ok.
// Print a message:
echo '<h1>Thank you!</h1>
<p>The link is now created. There will be a log in later.</p><p><br /></p>';
} else { // If it did not run ok.
// Public message:
echo '<h1>System Error</h1>
<p class="error"> The link could not be created due to a system error. We apologise for any inconvenience. </p>';
// Debugging message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' .$q . '</p>';
} // End of if ($r) IF.
// Include the footer and quit the script:
include ('includes/footer.html');
exit();
} else { // Report the errors.
echo '<h1>Error!</h1>
<p class="error">The following error(s) occured:<br />';
foreach ($errors as $msg) { // Print each error
echo " - $msg<br />\n";
}
echo '</p><p>Please again.</p><p><br /></p>';
} // End of if (empty($errors)) IF.
mysqli_close($dbc); // Close the database connection
} // End of the main a submit conditional.
?>
New Link
Intro:
Entry:
<?php if (isset($_POST['entry'])) echo $_POST['entry']; ?>
Title:
Link:
[/php]