Page 1 of 1

sql insert not working mysqli

Posted: Sat May 02, 2009 1:22 am
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,

Re: sql insert not working mysqli

Posted: Sat May 02, 2009 5:29 pm
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.