Results 1 to 4 of 4

Thread: INSERT INTO query??

  1. #1
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default INSERT INTO query??

    a newbie question here.

    what is the correct syntax to use with PHP for an INSERT INTO query to a MySQL database that resides on the same server.

    The server runs these versions

    • PHP version 5.2.6
    • MySQL version 5.0.77-community-log



    Code:
    <?php
    $link = mysql_connect('localhost', 'admin1', 'admin2');
    if (!$link) {
    	die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db('database', $link);
    if (!$db_selected) {
    	die('<p>unable to locate the database</p>');
    	}
    /* Insertion Query to store attributes into Database */
    mysql_query ("INSERT INTO tester 
    ('value1', 'value2') VALUES ('tested', 'successfully')")
    or die(mysql_error());  
    
    echo '<br />done successfully<br />';
    
    mysql_close($link);
    
    ?>
    The connection and database selection was successful. However I have labored for days on the right syntax to INSERT DATA with no luck, so i've turned to the forum for help. Thanks in advance.

  2. #2
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default INSERT INTO query??

    http://www.w3schools.com/php/php_mysql_create.asp

    follow this and you cannot go wrong.

  3. #3
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default

    Code:
    include "connect.php";
    $sql= "insert into tab_picture(picture,name) values ('$filename', '$name')";
    mysql_query($sql);
    sorry if i don't give the correct answer, but this is what i get form my class

  4. #4
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    The code looks just fine, what exactly goes wrong? Do you get a syntax error/mysql error?
    - Josh

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
  •