Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

mysqli_query not working (insertion into database)

$
0
0

hello,

 

I have just started working with php and encountered a problem in handling the MySQL database through my php script.

 

the code is as follows:

 

_______________________________________

 

<?php
        echo "successful!!";
        $first=$_POST['first'];
        $last=$_POST['last'];
        $email=$_POST['email'];
        
        $db=  mysqli_connect('localhost','root', 'akash123','akash') 
                  or die('Error in connecting to the database');
        echo "</br> successful conncetion";
        $query= "insert into info (first, last, email) values ($first,$last,$email)";
        echo "</br> successful query";
        $result= mysql_query($db,$query) or die("Error in insertion");
        echo "</br> successful insertion";
        mysqli_close($db);
        echo "the email ID of ".$first." ".$last." is ".$email;
        ?>
_______________________________________
 
And the output is as follows:
 
successful!!
successful conncetion
successful queryError in query
 
I understand that all the steps prior to mysqli_query function are functioning properly. The connection to the database is established, but it cant write into it.

Please help!

 

Viewing all articles
Browse latest Browse all 13200

Trending Articles