0

I Need Help What this :

PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/volvo/public_html/config.php:8 Stack trace: #0 /home/volvo/public_html/index.php(22): include() #1 {main} thrown in /home/volvo/public_html/config.php on line 8

How To Fix please... this is full my config code :

$dhost = "localhost"; //localhost
$dusername = "user232"; // user
$dpassword = "komplex56"; // pass
$ddatabase = "dvuhg"; // database

$con = mysql_connect($dhost, $dusername, $dpassword) or die("Cannot Connect"); 
mysql_select_db($ddatabase, $con);

if($_COOKIE["usNick"] and $_COOKIE["usPass"])
{
$q = mysql_query("SELECT * FROM tb_users WHERE username='{$_COOKIE['usNick']}' AND password='{$_COOKIE['usPass']}'") or die(mysql_error());
if(mysql_num_rows($q) == 0)
{
$_COOKIE['usNick'] = false;
$_COOKIE['usPass'] = false;
} else {
$loggedin = 1;
$r = mysql_fetch_array($q);
}
}
$da = date("j");

    $queryxx = "DELETE FROM ad_clicks WHERE day!='$da'";
mysql_query($queryxx);

$q2 = mysql_query("SELECT * FROM settings");
while($r2=mysql_fetch_array($q2))
{
$set[$r2[setname]]=$r2["setvalue"];
}
mysql_query("UPDATE settings SET setvalue='0', set_day='{$da}' WHERE set_day!='{$da}' AND set_day>'0'") or die(mysql_error());
$user=$_COOKIE['usNick'];
O. Jones
  • 92,698
  • 17
  • 108
  • 152
  • Why are you using the long-deprecated `mysql_` code library? It was discontinued many years ago and removed entirely in PHP7. No new code should be written using this library. It leaves you vulnerable to SQL injection attacks (due to the lack of parameterised query support) and potentially other unpatched vulnerabilities. Switch to using `mysqli` or `PDO` as soon as possible, and then learn how to write parameterised queries to protect your data from malicious input. See http://bobby-tables.com for a simple explanation of the risks and some sample PHP code to write queries safely. – ADyson Sep 22 '17 at 11:43
  • mysql_* functions are [deprecated](http://php.net/manual/en/migration55.deprecated.php). Switch to either [PDO](http://php.net/manual/en/book.pdo.php) or [mysqli](http://php.net/manual/ro/book.mysqli.php) – Andrei Sep 22 '17 at 11:43
  • There's a good chance your error is because either you're using PHP7, or this ancient library is (very sensibly) not installed/enabled in your particular installation. – ADyson Sep 22 '17 at 11:44
  • 2
    `mysql_` is gone! History! Nada! So if you are using PHP 7, it will throw that error as it has been removed. – Script47 Sep 22 '17 at 11:44
  • how to fix to PHP7 because i am still learn in php, thanks for answer – Kakashi2017 Sep 22 '17 at 11:45
  • the `mysql_` function are deprecated as of [PHP version 5.5.x](http://php.net/manual/en/migration55.deprecated.php) You should switch to [PDO](http://php.net/manual/en/ref.pdo-mysql.php) or [mysqli_](http://php.net/manual/en/book.mysqli.php) – Peter M Sep 22 '17 at 11:45
  • Also don't store secure data in cookies, nor in plain text, and dont put user data directly into a query (with `mysql_` you should use escaping, with `pdo` or `mysqli` parameterize). – chris85 Sep 22 '17 at 11:52
  • ok thx you all... – Kakashi2017 Sep 22 '17 at 12:05

1 Answers1

4

mysql_* has been removed therefore anything which uses PHP 7 or above cannot use the mysql_ extension.

You can use mysqli_* or PDO which are both more secure alternatives.

Script47
  • 13,644
  • 4
  • 41
  • 60
O. Jones
  • 92,698
  • 17
  • 108
  • 152