How do i fix uncaught error in 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

asked Apr 15, 2016 at 2:41

2

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)

answered Apr 15, 2016 at 2:52

How do i fix uncaught error in php?

Ruben FunaiRuben Funai

6095 silver badges5 bronze badges

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:


answered Apr 15, 2016 at 3:05

How do i fix uncaught error in php?

claudiosclaudios

6,5178 gold badges44 silver badges86 bronze badges

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

answered Apr 15, 2016 at 3:13

How do i fix uncaught error in php?

Not the answer you're looking for? Browse other questions tagged php mysql or ask your own question.

mysqli_db_query($db, "INSERT INTO CJ_UsersOnline VALUES ('$t_stamp','$REMOTE_ADDR','$PHP_SELF')") or die("Database INSERT Error"); 

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]

Educative Answers Team

How do i fix uncaught error in php?

Fatal errors crash the program. There are three types of fatal errors in PHP:

  1. Startup fatal error: This error occurs when a system can’t run the code during installation.

  2. Compile time fatal error: This error occurs if a call is made to a non-existent code or variable.

  3. Runtime fatal error: This error occurs while the program is running, and will cause the program to quit.

The following code tried to call a function name without declaring the function. This gives a fatal error:

Notice how the print statement is not executed. This is because, as soon as a fatal error is thrown, the code stops compiling.

Solution

  • Look for the undeclared variables as given in the error.
  • If you are using inbuilt functions, ensure that there is no typo and the correct function is called.
  • Check if the spellings are correct.

Copyright ©2022 Educative, Inc. All rights reserved

What is uncaught error in PHP?

When an exception is thrown, the code following it will not be executed, and PHP will try to find the matching "catch" block. If an exception is not caught, a fatal error will be issued with an "Uncaught Exception" message.

What is a solution for fatal error in PHP?

Solution. Look for the undeclared variables as given in the error. If you are using inbuilt functions, ensure that there is no typo and the correct function is called. Check if the spellings are correct.

What does fatal error uncaught error mean?

What Does Fatal Error Mean? A fatal error is an error that causes a program to terminate without any warning or saving its state. A fatal error, upon occurring, aborts the application currently running, and may cause the user to lose any unsaved changes made in the program.

How do I fix undefined errors in PHP?

Steps to Resolve the Error of Calling to Undefined Function in PHP.
Verify that the file exists. ... .
Verify that the file has been included using the require (or include ) statement for the above file on the page. ... .
Verify that the file name is spelled correctly in the require statement..