I have the following code, but it doesn’t work. I think it might be because the method was removed? Not sure what the new way to do it is though. I’m on wordpress.
<php?
mysql_query ("UPDATE $wpdb->users
SET access_key = $newAccessKey
WHERE ID = $currentUserID");
?>
That don’t work.
users is the table nome.
Advice??
This script is to be run on a page on php.
First you start with wrong syntax to start PHP script ‘
Now you should check the type of access_key if it is integer than you wrote right and if it is varchar or text then you should write with ”. For this your query is below.
I hope you will get solution.
use single quote for string vars and be sure for sanitize $wpdb->users use concat
The reason why it doesn’t work for you can be a number of things. You can find it out by enabling error reporting (
ini_set('display_errors', true); error_level(E_ALL);
) and checking for mysql errors (echo mysql_error();
).Second, if it wasn’t a typo when you were writing the question:
<php?
doesn’t start PHP code. It should be<?php
, the way you wrote it it is ignored both by the server and the browser because it is an illegal tag and the code inbetween isn’t executed at all.Apart from that,
$wpdb
brings its ownupdate()
function that you can use:That way you don’t have to worry about the database connection or deprecated functions.