Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:13:12+00:00 2026-06-02T09:13:12+00:00

I have used tutorials, examples and looked at numerous other questions about my problem

  • 0

I have used tutorials, examples and looked at numerous other questions about my problem and I still can’t get it to work, I am relatively new to PHP and do not have any understanding of PDO. I have changed my code to mysqli rather than mysql to get rid of the depreciated code my university gave me but they have been less than helpful during this situation.

If anyone could shed some light onto this issue for me I would be very grateful.
Below are my code samples:

<?php /*connect to the db */
   $link=mysqli_connect("dbhost","user","pass");
   mysqli_select_db("db",$link);

   /*checking connection*/
      if ($link->connect_errno) 
        throw new exception(sprintf("Could not connect: %s", $link->connect_error));

session_start();



        $insert_query="
        INSERT INTO testone_tbl (age,hours,flexibility,fastpaced,retailexp,
        workedus,conviction,permit,education)
        VALUES ('$age','$hours','$flexibility','$fastpaced','$retailexp','$workedus',
        '$conviction','$permit','$education'); 
        INSERT INTO testtwo_tbl 
        (contribute,insales,initiative,success,alternatives,targets,
        newthings,custfeed,incdevelop,standards,confident,stretch,
        opportunities,polite,ideas,deadline,supported,duties)
        VALUES ('$contribute','$insales','$initiative',
        '$success','$alternatives','$targets','$newthings',
        '$custfeed','$incdevelop','$standards','$confident','$stretch',
        '$opportunities','$polite','$ideas','$deadline','$supported','$duties')";


    /*execute multi_query*/


mysqli_multi_query ($link, $insert_query);/*error1*/
/*close connection*/
if(!$link>connect_errno) $link->close(); /*error2*/

?>

The data is both from the form this is written in (the last form) and sessions from the previous forms. However I am also getting this error: Warning: mysqli_multi_query() expects parameter 1 to be mysqli and Warning: mysqli_close() expects parameter 1 to be mysqliand I have been stuck on this the past few days! Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:13:13+00:00Added an answer on June 2, 2026 at 9:13 am

    You should first check with your web host if they have enabled multi-SQL-queries.

    Some web hosts only allow single-SQL queries to help prevent against injection attacks.

    If, however, you want to multi-insert to the same table, you could do it like this:

    INSERT INTO tbl_name (col1, col2)
         VALUES ('?', '?'),
                ('?', '?'),
                ('?', '?'); # inserts 3 records to the same table in one query
    

    Also, if you do have PDO available to you, use it!

    With a PDO object, your queries will be safer by using prepared statements. Example:

    $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    
    $data = array($col1, $col2, $col3);
    $sql = "INSERT INTO tbl_name (col1, col2, col3) VALUES ('?', '?', '?');";
    $query = $db->prepare($sql); # prepares the sql statement
    $query->execute($data); #binds the array of data to the ?
                            #question mark parameters, and executes.
    

    If you create a database abstraction layer, you could change the database connection mode without having to rewrite your code which executes your queries.

    Also, do you have a reason not to loop and query? Example:

    $sql_array = array("INSERT INTO tbl_one(col1) VALUES '?';",
                 "INSERT INTO tbl_two(col3) VALUES '?';");
    
    function performAll($sql_array) {
        # execute all of the queries
    }
    

    It has occured to me that you may be using some function to access your database connection. Now that is not a problem, unless you actually try to access the database connection from within a function (in case you have not told us). Example:

    $db = new PDO("...", $user, $pass);
    
    $query = $db->prepare($sql); # works fine
    
    function executeQuery($sql) {
        $query = $db->prepare($sql); # error: $db is not defined
                                     # within the scope of this function
        ...
    }
    

    To get around this, use the global keyword in PHP. Example:

    $db = new PDO("...", $user, $pass);
    
    function executeQuery($sql) {
        global $db; # use $db in the global scope
        $query = $db->prepare($sql); # works fine
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used JQuery for a small animation work: a table #photos contains 9
I have been watching Xcode tutorials on youtube and learning from examples online but
I have read the documentation, examples and tutorials of how to use the Google
I have recently uploaded a website for basic web designing tutorials with proper examples
I have looked at the php documentation, tutorials online and none of them how
I have the feeling that is easy to find samples, tutorials and simple examples
Most of the examples and tutorials I have found for the Facebook SDK are
I have used a tutorial to see how to implement JTable but I don't
I have recently used a PHP pagination tutorial, Pagination - what it is and
I have used the following as comments in my .emacs // {{{ // }}}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.