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