如何修复PHP中的致命错误?

如何修复PHP中的致命错误?

问题描述:

I found a system that can generate a report I would like to study this system but when I try to generate the system the login was OK but when I put the password and username this error comes out:

Fatal error: Call to undefined function mysql_select_db() in C:\xampp\htdocs\inventory\inventory\db.php on line 8

Can anyone else tell me what is the problem in this system?

image

I'm currently using XAMPP V3.2.2

我找到了一个可以生成报告的系统我想研究这个系统但是当我尝试生成系统时 登录没问题但是当我输入密码和用户名时出现这个错误: p>

致命错误:在 中调用未定义的函数mysql_select_db()C:\ xampp 第8行\ htdocs \ inventory \ inventory \ db.php p> blockquote>

其他人可以告诉我这个系统有什么问题吗? p> \ n

图片 p>

我是 目前正在使用XAMPP V3.2.2 p> div>

If you are using PHP 7 within your XAMPP then it wont work because that code is too old. mysql_select_db was removed in PHP 7.

http://php.net/manual/en/function.mysql-select-db.php

You will need to install PHP 5 to use that software.

Edit: Pratik Solanki is correct also. The database is being connected using mysqli so depending on the other code in the system you can either change the database connect statement to mysql_connect and use PHP 5 (old mysql connector not recommended) or change all the database statements to use mysqli instead in which case no PHP changes are needed (recommended)

You forgot to include the database while connecting using mysqli_connect function. In your code, you declared a $mysql_database but you didn't use that.

Code:

<php 
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "liveedit";

$bd = mysqli_connect ($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die ("Opps something went wrong ");
?>

You connected to database via mysqli module of php and you are trying to select your database via mysql module of php.

Correct way to use it would be like this :

mysqli_connect(dbhostname,dbusername,dbpassword,dbname)

mysqli can be used with the mysql native drivers and mysql can be used via the default libraries provided.

Both are different and the only small mistake you made was making connection with mysqli and selecting db with mysql.

Solution to this is making the whole connection along with selection of db via mysqli function