I just finished reading Build your own Database Driven Website by Kevin Yank and decided to edit some of the php so I could use the Administrative pages… I’m using the source code from chapter 9 in admin folder.
The only thing I’ve edited was changing “joke” to “article”. What i did was use Dreamweaver’s find/replace feature to replace every “joke” instance with “article”… I tipple checked everything to make sure “joke” instances were the only things that were changed (along with the associated MySQL table name) and caps/plurals are where they should be.
Everything seems to be fine with the revised code except whenever I try to submit a new article (joke) or delete an author, I get:
[B]when I try to submit article:[/B]
Error adding submitted article.
[B]When I try to delete author:[/B]
Error getting list of articles to delete.
admin>jokes>index.php>lines 68-92
if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
$text = mysqli_real_escape_string($link, $_POST['text']);
$author = mysqli_real_escape_string($link, $_POST['author']);
if ($author == '')
{
$error = 'You must choose an author for this article.
Click ‘back’ and try again.';
include 'error.html.php';
exit();
}
$sql = "INSERT INTO article SET
articletext='$text',
articledate=CURDATE(),
authorid='$author'";
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted article.';
include 'error.html.php';
exit();
}
I’m guessing the problem is in this portion of the jokes index located in admin folder, but it’s identical to the original source code except for “article” so I’m stuck because my includes folder is updated and it can’t be a connection issue with MySQL because the rest of the scripts are running fine. Any suggestions as to what the problem might be?
I see an “id” column, but not “authorid”. The column names you use in SELECT statements (and all other statements for that matter) must match them exactly as they’re written. =)
I think adding authorid might have fixed the issue, I’m checking if it will disorient the rest of my code. Since I’m using the source code from chapter 9, didn’t think it would be an issue, thanks samanime!