sql insert not working mysqli

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

sql insert not working mysqli

Post by pinehead18 »

Code: Select all

<?PHP
    
    $mysqli = new mysqli("localhost","","");
    
    if(mysqli_connect_errno()){ 
        printf("Connection failed", mysql_connect_errono());
        exit();
    }
    
    $query = "INSERT INTO dev (id, username, password, email) VALUES ('1', 'pinehead','', 'pinehead@owned.com')";
    $mysqli->query($query);
    
printf("ID?:", $mysqli->insert_id);
    
    
    
    
    
?>
   
Re-learning php5 with object oriented programming. Using mysqli. However, i use this insert command in phpmyadmin and it works. But nothing displays and no errors when i access the page.

Thoughts?

Thanks,
Last edited by Benjamin on Sat May 02, 2009 2:35 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: sql insert not working mysqli

Post by McInfo »

The printf() format strings on lines 6 and 13 are missing directives.

PHP Manual: sprintf

On line 6, mysql_connect_errono() should be mysqli_connect_errono(). (Notice the "i".)

Edit: This post was recovered from search engine cache.
Post Reply