简体   繁体   中英

mysql_query is not working as expected

$query = mysql_query("SELECT * FROM joblist WHERE salary LIKE '%$searchq%' OR jobtitle LIKE '%$searchq%'");
$count = mysql_num_rows($query);
if ($count == 0){
    $output = 'There was no search results!';
}else {
    while($row = mysql_fetch_array($query)) {
        $salary = $row['$salary'];
        $jobtitle = $row['$jobtitle'];
        $id = $row['id'];
        $output .= '<div>' .$salary.' '.$jobtitle.'</div>';
    }
}

Fatal error:

Call to undefined function mysql_query() in /srv/http/head.php on line 16

You can use mysqli_* if you are using PHP 7. Because mysql_* is not available in this version. Here is the example that you can use it.

<?php

// procedural style of mysqli

$host = "host";
$user = "user";
$password = "password";
$database = "db";

$link = mysqli_connect($host, $user, $password, $database);

if(!$link){
    echo ('unable to connect to database');
}
else {
$sql = "your select query";
$result = mysqli_query($link,$sql);
    if(mysqli_num_rows($result) == 1){
  // SUCCESS STUFF
}
else {
 // error stuff
}
} // end else

?>

Mysql_* has been depreciated from PHP 7.0 and onwards. Please use mysqli_*. Or else downgrade your PHP version to 5.6 or lower. It will work fine. https://www.php.net/manual/en/function.mysql-connect.php ( see the waning section of this page).

The PHP extension for mysql is not installed/configured on your system.

Try

This being said, you should use mysqli (not mysql ) extension, as mysql is deprecated, not recommended and will be out of PHP7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM