jeudi 23 juin 2016

Why is this INSERT not working? (PHP MySQL)

I'm simply trying to insert a record into a MySQL databse. Why is this not working? File name: insert.php <?php $l_dbhost = "x.x.x.x"; $l_dbuser = "dbuser"; $l_dbpass = "password"; $l_db = "db"; $l_table = "db.users"; $l_datetime = date_create()->format('Y-m-d H:i:s'); $l_username = "bob"; $l_password = "bobpass"; $db_conn = mysqli_connect($l_dbhost, $l_dbuser, $l_dbpass, $l_db) or die("Failed to connect!"); $db_query = "INSERT INTO $l_table (username, password, lastUpdate) VALUES ('$l_username', '$l_password', '$l_datetime')"; echo $db_query . "n"; $db_result = mysql_query($db_conn, $db_query) or die("Failed to update table!"); ?> Here is the output from executing 'php insert.php'... INSERT INTO users (username, password, lastUpdate) VALUES ('bob', 'bobpass', '2016-06-22 21:03:06') PHP Warning: mysql_query() expects parameter 1 to be string, object given in /var/www/example.com/insert.php on line 19 Failed to update table! MySQL table info: mysql> describe users; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | username | varchar(45) | NO | PRI | NULL | | | password | varchar(45) | YES | | NULL | | | lastUpdate | datetime | YES | | NULL | | +------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) Thanks for your feedback! TXBrew

Aucun commentaire:

Enregistrer un commentaire