SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding command for MySQL

    I am learning PHP through a book ("SAMS: PHP & MySQL Web Developement"), and the way it explains how to insert new records into databases is the following:
    Code:
    $query = "insert into books values
               ('".$isbn."', '".$author."', '".$title."')";
    But its not working? and it doesnt really explain what those variables are, though i would think they are the values going into the DB. Can anyone help?

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    Please post more codes,not just one line so that someone here can help you.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry:

    Code:
    @ $db = mysql_connect("localhost", "bookorama", "bookorama");
    mysql_select_db("books");
    $query = "insert into books values
             ('".$isbn."', '".$author."', '".$title."')";
    $results = mysql_query($query);
    that is the example code that the book provides. But it doesnt work for me on f2s.com. I go to browse my table and it is empty.

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you assigning values to $isbn, $author, and $title somewhere?
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes.

  6. #6
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it resulting in any form of error? Or does the script process correctly?
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  7. #7
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    are you assigning values to $isbn, $author, and $title somewhere?
    Please give us a specific example of this values, ie, $author = "...., etc

  8. #8
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Might help if you get mysql to report any errors.
    PHP Code:
    If you replace;

    $results mysql_query($query);

    with

    if ( !$results mysql_query($query) ) {
           echo ( 
    "<p>" mysql_error() );

    At least you have an idea then where the problem lies.

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also is isbn in the primary key. If there is an extra column in there like an auto-incrementing, then using the INSERT ... VALUES (.....) needs to have an arg for every field in the table. Try using SET instead

    PHP Code:
    $query "insert into books set isbn = '$isbn', author = '$author', title = '$title'";
    $result mysql_query($query) or DIE(mysql_error()); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is that code for a form of any sort. That's probaly is where your variables "('".$isbn."', '".$author."', '".$title."')";" might be set...
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW


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
  •