0

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 :)

1
  • post your mysqli connection code.. $connection Commented Mar 27, 2013 at 1:49

2 Answers 2

2

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..

Sign up to request clarification or add additional context in comments.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.