www.webdeveloper.com
Results 1 to 7 of 7

Thread: PHP and SQLi connection problems: mysqli_query() expects at least 2 parameters

  1. #1
    Join Date
    Apr 2014
    Posts
    38

    PHP and SQLi connection problems: mysqli_query() expects at least 2 parameters

    Hi Guys as some of you are aware, I'm creating my own website and I want users to register

    Config.php
    Code:
    <?php 
    
    $con=mysqli_connect("localhost","root","","registration");
    
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    
    mysqli_close($con);
    ?>
    submit_form.php
    Code:
    <?php
    //select your database
    //$b=mysql_select_db("database_name",$a);
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $username=$_POST['username'];
    //$confirmusername=$_POST['confirmusername'];
    $password=$_POST['password'];
    $confirmpassword=$_POST['confirmpassword'];
    $email=$_POST['email'];
    $confirmemail=$_POST['confirmemail'];
    //Database connection
    require_once("config.php");
    //mysql query to insert value to database
    $query="INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username', '$password', '$confirmpassword', '$email' , '$confirmemail')";
    
    $result = mysqli_query($query);
    //if value inserted successyully disply success message
    if(!$result) {
    
        die("The following SQL Failed $query");
    }
    echo 'Registred successfully..!!</div>';
    ?>
    and this is now the error I'm getting can anyone help me out with it?


    Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\submit-form.php on line 17
    The following SQL Failed INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('richard', 'Hemmings', 'hemmo001', 'password', 'password', 'richardgwhemmings@msn.com' , 'richardgwhemmings@msn.com')

  2. #2
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    No password in connect string. Also try include "Config.php" Ensure the path for config.php is correct.

  3. #3
    Join Date
    Apr 2014
    Posts
    38
    there is no password to the database as the last time i did this i buggerd up xampp and phpmyadmin

  4. #4
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    This would probably be the password you use to log in to PHP MyAdmin

  5. #5
    Join Date
    Apr 2014
    Posts
    38
    there should be but I haven't got one to be honest. I dont want to put on in there as last time it took me nearly 2 weeks to get xampp working again and i accidentally lost all of the work that i did for my website

  6. #6
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    So when you log on to PHP MyAdmin, what password do you use? How do you log in since it required username and password?

  7. #7
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    If you are using a hosting service, it might be your username and password to get to your cpanel

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles