0

Hi,
I'm trying to write a program using mysqli, so I have created a login page. I've tried looking for how to get an Insert statement ran using MySQLi, object orientated style.

So it looks like my query isn't working but I don't know why so I wondered if someone could help.

My code is self-explanitory, I'm just using constants to connect to the mysql server, and the form is posting. I am connected to the MySQL server. Vardump of $query is: bool(false) .

 <?php
    include('../functions.php');
    $mysql=db_connect(HOST,USER,PASSWORD,DB);
    $query=false;
    var_dump($_POST);
    if (isset($_POST['username']))
    {
        $user=$_POST['username'];
    }

    if (isset($_POST['password']))
    {
        $password=pword_encrypt($_POST['password']);
    }

    $query=run_query($mysql,"INSERT into users (username,password) VALUES ('$user','$password')");
    var_dump($query);
?>

And my functions.php:

function db_connect($dbhost,$dbuser,$dbpassword,$dbselect)
{
    $mysql=new mysqli();
    $mysql->connect($dbhost,$dbuser,$dbpassword,$dbselect);
    return $mysql;
}
function run_query($mysql,$sql)
{
    $result=$mysql->query($sql);
    return $result;
}

Thanks,
Ben

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by LastMitch
0

@bsewell

My code is self-explanitory, I'm just using constants to connect to the mysql server, and the form is posting. I am connected to the MySQL server. Vardump of $query is: bool(false)

Like what iamthwee said what error messages you are getting?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.