Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: MySQL

  1. #1
    Member
    Join Date
    Apr 2004
    Posts
    58
    Member #
    5497
    PHP Code:
       $insert mysql_query("INSERT INTO KJV('verseID', 'book_f', 'book_s', 'chapter', 'verseno', 'versetext')
                        VALUES('', 
    $book_full$book_short$cur_chapter$verseno$verse)"$MySQL_Connection); 
    What is wrong with my code? It isn't doing anything.

  2.  

  3. #2
    Senior Member jlgosse's Avatar
    Join Date
    Jan 2004
    Location
    Newfoundland, Canada
    Posts
    1,037
    Member #
    4570
    Liked
    7 times
    Try something like:
    PHP Code:
    $sql "INSERT INTO table01 ( 'field01' , 'field02' , 'field03' , 'field04' ) VALUES ( 'value01' , 'value02' , 'value03' , 'value04' )";
      
    mysql_query($sql); 
    That should do it.

    Also, did you connect to the database first, before you tried the query? What error do you get?


  4. #3
    Member
    Join Date
    Apr 2004
    Posts
    58
    Member #
    5497
    I am actually a very experienced PHP and MySQL developer, I just couldn't find what was wrong. That's the thing: I don't get an error. But it doesn't insert into my database either.

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Try removing the quote marks you have around fieldnames, and leave them around the values.
    S. Rosland

  6. #5
    Member
    Join Date
    Apr 2004
    Posts
    58
    Member #
    5497
    Neither is working.

  7. #6
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Try to write your query into a separate variable:
    $sql="INSERT INTO tableName (field1, field2...) VALUES ('$var1', '$var2'..)";

    Then echo the variable $sql to see what it's actually passing to the 'mysql_query()' function.
    S. Rosland

  8. #7
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    BTW, if you're not going to insert anything into the first field, you don't need to list it in the 'fields' block (or the values block).

    The only time you need to specify an empty column, is if you're trying to INSERT without specifying the field names. In that case,the query will try to insert values in all existing field names, in order they are listed in the table.
    S. Rosland

  9. #8
    Member
    Join Date
    Apr 2004
    Posts
    58
    Member #
    5497
    I did what you mentioned, and what it is sending to the MySQL server is valid.

  10. #9
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Try to write it manually into phpmyadmin or MySQLCC, and see if it updates. If it does (and it should if you write it like I outlined), then the error is PHP related.

    Try first to add a'die' message like so:
    PHP Code:
    $insert=mysql_query($sql) or die("Error message: ".mysql_error()); 


    That will print the part of the query that is causing the error, to screen.
    S. Rosland

  11. #10
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Run the resulting query in phpMyAdmin. It is likely getting an error.

    Most complex PHP scripts (including vBulletin) write a class that vastly extends the functionality of MySQL calls directly, including (most importantly) error detection.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:44 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com