For SELECT, SHOW, DESCRIBE, EXPLAIN, and other queries that return a result from multiple rows, mysql_query () returns a handle to the result of the query (resource), or FALSE if an error occurs. Official documentation
The error is that any text values must be in quotes, and it is passed to you as a column name and, accordingly, MySQL cannot find such a column in the table and throws the answer that the query is erroneous. That's true (but not quite):
$query="SELECT * FROM `".$mysql_table."` WHERE `code`='".$link."'"; $sql_result=mysql_query($query); if (!$sql_result) { die('Неверный запрос: ' . mysql_error()); } $row=mysql_fetch_assoc($sql_result);
In general, in no case do not try to use the outdated mysql extension and substitute parameters in a similar way, you doom yourself to the torment associated with the possibility of hacking and the lack of support in future versions. After all, if the link parameter comes from a user, I, as a user, can slightly change your query (read more: SQL injections) and get the data that I need. Unless of course you pre-do type checking, etc.
Correctly build a query through PDO or MySQLi using named parameters that prevent global change of the query. Example via PDO:
try { $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); $sql = 'SELECT * FROM table WHERE code = :code'; $sth = $dbh->prepare($sql); $sth->execute([':code' => $link]); $result = $sth->fetchAll(); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); }
".$mysql_table."SETcode= '". $ link_short. "' WHERElink_id= '". $ row [' link_id ']. "'" "; mysql_query ($ query); - Sergey Kiryakov".$mysql_table."SETlink_hash= '". $ link_hash. "',link_url= '". mysql_real_escape_string ($ link_url). "'"; mysql_query ($ query); - Sergey Kiryakov