Morning guys, I am trying to display a custom error page called “article_submission_error.php” if the article is not submitted to the database. I don’t know how to display the page if there is an error. Perhaps we could use the code below but I don’t know what the $error variable would be or how to trip that. Below you will see my query and the html page that I am using.
PS: i dont have any PDO extensions just regular php
if($error) {
include ‘path/to/error.php’;
exit;
[code]
function newArticle($db, $userID, $articleTitle, $articleSummary, $articleContent, $publicationDate)
{
$query = ‘insert into Articles
(
publicationDate,
articleTitle,
articleSummary,
articleContent,
userID)
VALUES
(
:publicationDate,
:articleTitle,
:articleSummary,
:articleContent,
:userID
)’;
Html Page with fields
[code]
<!DOCTYPE html>
<html lang=”en” xmlns=”http://www.w3.org/1999/html”>
<HEAD>
<meta charset=”UTF-8″>
<title><?php include (‘title.php’) ?></title>
</HEAD>
<BODY>
<?php include (‘sections/menubar.php’) ?>
<?php //include( ‘sections/searchBar.php’ );
<section id=”addParagraphSection”>
<header><h1>Add New Article </h1></header>
<form action=”addNewArticles.php”<?php //”sections/queries.php”*/?> method=”post” id=”addNewArticle”>
<table>
<tr>
<td><label>Article Title:</label></td>
<td><input type=”text” name=”articleTitle” required></td>
</tr>
<tr>
<td><label>Article Summary:</label></td>
<td><textarea rows=”3″ cols=”70″ name=”articleSummary” ></textarea></td>
</tr>
<tr>
<td><label>Article Content:</label></td>
<td><textarea rows=”22″ cols=”70″ name=”articleContent” ></textarea></td>
</tr>
<tr>
<td><label>Start Publishing Date:</label></td>
<td><input type=”date” name=”publicationDate” required value=”<?php echo date(‘Y-m-d’); ?>”></td>
</tr>
</table>
<input type =”hidden” name=”newArticle” value=”new”>
<input type =”hidden” name=”ID” value=”<?php echo $ID ?>”>
<input type =”hidden” name=”user” value=”<?php echo $_SESSION[‘user’]?>”>
<input type=”submit” name=”submit” value=”submit”>
<button type =”reset” value=”reset”>reset</button>
<button type=”button” onclick=”history.go(-1);”>Back </button>
</Form>
</section>
<footer>
<?php include( “sections/footer.php” ); ?>
</footer>
</BODY>
</HTML>