#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Lindale, TX
    Posts
    256
    Rep Power
    15

    Simple PHP/MySQL Question


    Hi,

    It has been a while and PHP has changed. I am having what is probably a simple issue just inserting a few variables into a MySQL table.
    PHP7

    Error recieved: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /var/www/html/portal/engine/add_user_engine.php on line 17
    Error adding record to MySQL

    Does anyone see a glaring issue with the code? The columns are correct.


    Code:
    <?php
    //Add New User engine
    
    include '/var/www/html/portal/db.php';
    
    $email_given = $_POST['email_given'];
    $password_given = $_POST['password_given'];
    $firstname_given = $_POST['firstname_given'];
    $lastname_given = $_POST['lastname_given'];
    $security_given = $_POST['security_given'];
    $school_id_given = $_POST['school_id_given'];
    $user_status_given = $_POST['user_status_given'];
    
    echo "email given = $email_given";
    
    $sql_add_user = "INSERT INTO users ('user_id', 'email', 'password', 'firstname', 'lastname', 'security', 'school_id', 'user_status') VALUES ('', '$email_given', '$password_given', '$firstname_given', '$lastname_given', '$security_given', '$school_id_given', '$user_status_given')";
    if ($result_query = mysqli_query($sql_add_user, $ukmaa_db)) {
        header('location:http://portal.ukmaa.com/admin/edit_user.php?email_given=$email_given');
    } else {
        echo "Error adding record to MySQL";
    }
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Lindale, TX
    Posts
    256
    Rep Power
    15
    DB.php


    Code:
    <?php
    //UKMAA MySQL DB Connection Options
    
    
    $db_name = 'db';
    $username = 'user';
    $password = 'mypass';
    $servername = '127.0.0.1';
    $db = 'db';
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password);
    $ukmaa_db = mysqli_select_db($conn, $db);
    
    // Check connection
    if ($conn->connect_error) {
        die("MySQL Connection failed: " . $conn->connect_error);
    }
  4. #3
  5. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,794
    Rep Power
    9646
    That's not even the worst problem...

    Was this code converted from the mysql_* functions?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Lindale, TX
    Posts
    256
    Rep Power
    15
    No, but I havent coded since then so..


    Originally Posted by cadams
    DB.php


    Code:
    <?php
    //UKMAA MySQL DB Connection Options
    
    
    $db_name = 'db';
    $username = 'user';
    $password = 'mypass';
    $servername = '127.0.0.1';
    $db = 'db';
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password);
    $ukmaa_db = mysqli_select_db($conn, $db);
    
    // Check connection
    if ($conn->connect_error) {
        die("MySQL Connection failed: " . $conn->connect_error);
    }
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Lindale, TX
    Posts
    256
    Rep Power
    15
    I fixed it. Thanks
  10. #6
  11. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,794
    Rep Power
    9646
    Please, please don't develop on your live site. Especially when someone can come around and break everything because you don't know about SQL injection (remember that "worst problem" I hinted at?) and have other bugs in your code.

IMN logo majestic logo threadwatch logo seochat tools logo