Hi,

Please I have a problem inserting record to mysql database, it always shows this error " Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www"

here is my code

            <?php 

            if(isset($_POST['submit'])){
             $member_dat1=$_POST['member_first'];
             $member_dat2=$_POST['member_lastname'];
             $member_dat3=$_POST['sex'];
             $member_dat4=$_POST['member_type'];
             $member_dat5=$_POST['m_email1'];
             $member_dat6=$_POST['m_phone1'];
             $member_dat7=$_POST['m_address1'];
             $member_dat8=$_POST['m_address2'];
             $member_dat9=$_POST['city'];
             $member_dat10=$_POST['state'];
             $member_dat11=$_POST['added_by'];

             $member_insert= "INSERT INTO members(member_first,member_lastname,sex,member_type,m_address1,m_address2,city,state,m_phone1,m_email1,added_by)"
                     . " VALUES ('$member_dat1','$member_dat2','$member_dat3','$member_dat4','$member_dat5','$member_dat6','$member_dat7','$member_dat8','$member_dat9','$member_dat10','$member_dat11')";

            /* @var $connection type */
             $result = mysqli_query($connection, $member_insert);
                // execute the SQL statement
             if ($result) {
             echo "Congratulations <b> $_POST[member_first] </b> your Registration is successful!";
             } else {
             echo "Sorry! User Registration Fail";
             }

            }
             ?>

Thanks.

My connection to database is ok but i still get the error message.

            what is the appropraite way of inserting into MySqli using mysqli_query().

            see my code below
            $link = mysqli_connect("localhost", "root", "grut", "m_crm");

             $result = mysqli_query($link, $member_insert );

             if ($result) {
             echo "Congratulations <b> $_POST[member_first] </b> your Registration is successful!";
             } else {
             echo  "Sorry! User Registration Fail";
             }

Thanks.

Member Avatar for diafol

This is flying in the face of logic. Cereal pointed out the issue. $connection as a passed param is NULL. What does that tell you? That your connection is fine? By the time you come to execute the query, $connection is NULL regardless if you set it upstream (or think you did).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.