Reputation: 273
I am having problems updating mysql with php using varables.
mysqli_query($connection, "UPDATE passwords SET used=1, time_used='{$time}'
WHERE password='{$key}'
");
I was given the error:
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\wamp\www\key_check.php on line 47
any ideas why?
Thanks!
EDIT: Whole Code: http://pastebin.com/raw.php?i=W5cx8pBP
The "new mysqli" solution seems to be giving problems when trying to
$result = mysql_query("SELECT * FROM passwords", $connection);
Thanks :)
Upvotes: 0
Views: 60
Reputation: 2713
Your connection setting must look like
$connection = new mysqli($host,$username,$pass,$db);
Then execute the query using your way or by this way also
$query="UPDATE passwords SET used=1, time_used='{$time}'
WHERE password='{$key}'
";
$stmt = $connection->query($sql);
note: using prepared statements for mysqli can also possible and great. By somehow you also needed to bind parameters in there..
Upvotes: 2
Reputation: 10564
You have to declare $connection by creating a new mysqli object. If you fail to do so, you can check the documentation for mysqli constructor
Here's the code from the documentation.
$connection = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if ($connection->connect_error) {
die('Connect Error (' . $connection->connect_errno . ') '
. $connection->connect_error);
Upvotes: 1