SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    when I try to submit article:
    Error adding submitted article. 
    
    When I try to delete author:
    Error getting list of articles to delete.
    admin>jokes>index.php>lines 68-92
    Code:
    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?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Off Topic:

    Quote Originally Posted by dcd018 View Post
    I tipple checked everything ...
    it's not wise to drink and code...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha, I just loled.. irony wasn't what I was aiming for. It's not even noon!

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    test your sql statements outside of php, i.e. directly in mysql

    that way you'll get the actual mysql error message
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I tested

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

    Code:
    #1054 - Unknown column 'authorid' in 'field list'
    However, when I run

    Code:
    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.

    Code:
    id 	name      email 	                 password
    1 	John     John@mail.com      d8a6582c02d188df9ad89a6affa412f7
    Thanks for the suggestion

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    could you do a SHOW CREATE TABLE for the article table please
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    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. =)

  8. #8
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Code:
    Table 	         Create Table
    article 	 CREATE TABLE `article` (
                    `id` int(11) NOT NULL A...
    Solved... I hope

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A table called 'article' with absolutely no columns for article related data is a bit weird, huh?
    Quote Originally Posted by r937 View Post
    it looks like you might've renamed your user table as the article table
    Patriotism is the virtue of the vicious.

  11. #11
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    as miracle max said in the princess bride, "i've seen worse"

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •