0

how would I convert this code below to work with php7?

else {
    $sql = "SELECT u.`steps`, c.`cityname` FROM `users` u LEFT JOIN `cities` c ".
           "ON u.`location` = c.`cityid` WHERE u.`userid` = '{$ir['userid']}'";
    $run = mysql_query($sql);
    $res = mysqli_fetch_array($run, MYSQL_ASSOC);


    $city_name  = $res['cityname'];
    $city_turns = $res['steps'];
Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34
Samad
  • 1
  • Pretty sure when you use prepared statements you always fix the error as string interpolation for any SQL query is a absolute **no go** ... See [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) (i also marked it as duplicate) – Raymond Nijland Jul 26 '19 at 09:31
  • .. If thats not the case... *"Query which works on php 5.6 not throwing error on php 7"* enable debugging mode PHP or check the error_log and provide us with a error.. – Raymond Nijland Jul 26 '19 at 09:35
  • 1
    Possible duplicate of [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Sami Ahmed Siddiqui Jul 26 '19 at 09:50
  • I believe that mysql_query call needs to go. You should take a look at [Can I blindly replace all mysql_ functions with mysqli_?](https://meta.stackexchange.com/questions/121422/use-hyperlink-in-comment). – Booboo Jul 26 '19 at 16:36
  • Possible duplicate of [How to change mysql to mysqli?](https://stackoverflow.com/questions/1390607/how-to-change-mysql-to-mysqli) – ADyson Jul 26 '19 at 18:52

1 Answers1

1

From the docs for mysql_query:

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.

That'd be yer problem then.

It goes on to say:

Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

I recommend taking the PDO route.

Please note for future questions: always include the error message - verbatim - in the question text, yeah? Cheers.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78