Kevin Yank - Database Driven Website

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?

[ot]

it’s not wise to drink and code… ;)[/ot]

Haha, I just loled… irony wasn’t what I was aiming for. It’s not even noon!

test your sql statements outside of php, i.e. directly in mysql

that way you’ll get the actual mysql error message

Ok, I tested

INSERT INTO article SET
articletext='$text',
articledate=CURDATE(),
authorid='$author'

And got

#1054 - Unknown column 'authorid' in 'field list'

However, when I run

INSERT INTO article SET
articletext='$text',
articledate=CURDATE();

My “article” table gets updated

So here’s what my “article” table looks like, and I still have no clue what the problem is since there’s an id column in my field list.

id 	name      email 	                 password
1 	John     John@mail.com      d8a6582c02d188df9ad89a6affa412f7

Thanks for the suggestion :hangin:

could you do a SHOW CREATE TABLE for the article table please

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!

@r937

Table 	         Create Table
article 	 CREATE TABLE `article` (
                `id` int(11) NOT NULL A...

Solved… I hope

according to post #5, your article table has columns id, name, email, and password

i couldn’t see anything beyond id in your last post, eh

it looks like you might’ve renamed your user table as the article table

but if you say it’s solved, then carry on

:slight_smile:

A table called ‘article’ with absolutely no columns for article related data is a bit weird, huh?

as miracle max said in the princess bride, “i’ve seen worse”

:cool: