SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2003
    Location
    California
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy help with 'Database Driven Website' book

    HI,

    I'm really new at PHP and I have been going through Kevin Yank's book..Database Driven Website...

    I am trying to get the jokes database to work... Here is my dilema (I'm sure I'm missing something VERY obvious).

    I have created the jokes database with two tables, one for jokes the other for authors. I have been able to get the code to post the information needed into the database except that for some reason the AID in the jokes table is not getting updated with each new author. I thought (maybe wrongly so) that I needed to tell the script to update the jokes table with the AID information. Only problem is that I cannot figure out how to get it done. And of course, until the jokes have an AID they won't show up on the web page after they have been posted. Here's the portion of my code I think that I need to fix, also and attempt to try and fix it.

    Can someone help me?

    This code posts to the database but doesn't create the AID or post on the webpage

    PHP Code:
         //If a joke has been submitted,
         //add it to the database.
         
    if (isset($_POST['submitjoke'])) {
            
    $joketext $_POST['joketext'];
            
    $name $_POST['name'];
            
    $email $_POST['email'];
            
    $sql "INSERT INTO Jokes SET
                 JokeText='
    $joketext',
                 JokeDate=CURDATE()"
    ;
                 
    "INSERT INTO Authors SET
                 Name='
    $name',
                 EMail='
    $email'";
            if (@
    mysql_query($sql)) {
                 echo(
    '<p>Your joke has been added.</p>');
            } else {
              echo(
    '<p>Error adding submitted joke: ' .
                             
    mysql_error() . '</p>');
            }
         } 
    The next code is what I think I might need to do ( or something like this) but it doesn't work....
    PHP Code:
    //If a joke has been submitted,
         //add it to the database.
         
    if (isset($_POST['submitjoke'])) {
            
    $joketext $_POST['joketext'];
            
    $name $_POST['name'];
            
    $email $_POST['email'];
            
    $id $_POST['id'];
            
    $sql "INSERT INTO Jokes SET
                 JokeText='
    $joketext',
                 JokeDate=CURDATE()"
    ;
                 
    "INSERT INTO Authors SET
                 Name='
    $name',
                 EMail='
    $email'";
                 
    "GET FROM Authors
                 ID='
    $id'";
                 
    "INSERT INTO Jokes SET
                 AID='
    $id'";
            if (@
    mysql_query($sql)) {
                 echo(
    '<p>Your joke has been added.</p>');
            } else {
              echo(
    '<p>Error adding submitted joke: ' .
                             
    mysql_error() . '</p>');
            }
         } 
    Thanks so much,

    -kreid

  2. #2
    SitePoint Member
    Join Date
    Dec 2003
    Location
    California
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ugh!!

    Ugh...Now after reading further in the book I can see that I have wanted too much too soon.

    Step by step is the way to go.

    -kreid


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
  •