What's new

Help Help sa error sa php

choiniglory03

Honorary Poster
Established
Joined
Jun 1, 2018
Posts
157
Reaction
456
Points
203
Age
30
Fatal error: Uncaught ArgumentCountError: mysqli_select_db() expects exactly 2 arguments, 1 given in C:\xampp\htdocs\gw\config.php:9 Stack trace: #0 C:\xampp\htdocs\gw\config.php(9): mysqli_select_db('grading') #1 C:\xampp\htdocs\gw\index.php(2): include('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\gw\config.php on line 9
ito codes ko

<?php
session_start();
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'grading';

mysqli_connect($host,$user,$pass) or die(mysql_error());
mysqli_select_db($db);

?>
 
The error message you are encountering states that the function mysqli_select_db() expects exactly two arguments, but you only provided one in your code.

To fix this issue, you need to pass both the database connection and the name of the database as arguments to the mysqli_select_db() function.

Here's the corrected code:

PHP:
<?php
    session_start();
    $host = 'localhost';
    $user = 'root';
    $pass = '';
    $db = 'grading';

    $conn = mysqli_connect($host, $user, $pass) or die(mysqli_error());
    mysqli_select_db($conn, $db);

?>

In the above code, I've stored the result of mysqli_connect() in the $conn variable and passed it as the first argument to mysqli_select_db(). The name of the database 'grading' is passed as the second argument.
 
The error message you are encountering states that the function mysqli_select_db() expects exactly two arguments, but you only provided one in your code.

To fix this issue, you need to pass both the database connection and the name of the database as arguments to the mysqli_select_db() function.

Here's the corrected code:

PHP:
<?php
    session_start();
    $host = 'localhost';
    $user = 'root';
    $pass = '';
    $db = 'grading';

    $conn = mysqli_connect($host, $user, $pass) or die(mysqli_error());
    mysqli_select_db($conn, $db);

?>

In the above code, I've stored the result of mysqli_connect() in the $conn variable and passed it as the first argument to mysqli_select_db(). The name of the database 'grading' is passed as the second argument.
Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\gw\index.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\gw\index.php on line 7
codes

<?php
include('config.php');
if(isset($_POST['submit'])){
$user = $_POST['user'];
$pass = $_POST['pass'];
$query = "select * from userdata where username='$user' and password='$pass'";
$r = mysql_query($query);
if(mysql_num_rows($r) == 1){
$row = mysql_fetch_assoc($r);
$_SESSION['level'] = $row['level'];
$_SESSION['id'] = $row['username'];
$_SESSION['name'] = $row['fname'].' '.$row['lname'];
header('location:'.$row['level'].'');
}else{
header('location:index.php?login=0');
}
}

if(isset($_SESSION['level'])){
header('location:'.$_SESSION['level'].'');
}
?>
 
Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\gw\index.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\gw\index.php on line 7
codes

<?php
include('config.php');
if(isset($_POST['submit'])){
$user = $_POST['user'];
$pass = $_POST['pass'];
$query = "select * from userdata where username='$user' and password='$pass'";
$r = mysql_query($query);
if(mysql_num_rows($r) == 1){
$row = mysql_fetch_assoc($r);
$_SESSION['level'] = $row['level'];
$_SESSION['id'] = $row['username'];
$_SESSION['name'] = $row['fname'].' '.$row['lname'];
header('location:'.$row['level'].'');
}else{
header('location:index.php?login=0');
}
}

if(isset($_SESSION['level'])){
header('location:'.$_SESSION['level'].'');
}
?>
The error message you received indicates that the function mysql_query() is undefined. This error occurs because you are using the deprecated MySQL extension instead of the MySQLi extension.

To fix the issue, you need to update your code to use the MySQLi extension instead. Here's the modified code:

PHP:
<?php
    include('config.php');
    if(isset($_POST['submit'])){
        $user = $_POST['user'];
        $pass = $_POST['pass'];
        $query = "select * from userdata where username='$user' and password='$pass'";
        $r = mysqli_query($conn, $query);
        if(mysqli_num_rows($r) == 1){
            $row = mysqli_fetch_assoc($r);
            $_SESSION['level'] = $row['level'];
            $_SESSION['id'] = $row['username'];
            $_SESSION['name'] = $row['fname'].' '.$row['lname'];
            header('location:'.$row['level'].'');
        }else{
            header('location:index.php?login=0');
        }
    }

    if(isset($_SESSION['level'])){
        header('location:'.$_SESSION['level'].'');
    }
?>

In this code, I assume that you have already established a database connection in your config.php file and stored it in the $conn variable. I also replaced the mysql_query() function with mysqli_query() and mysql_num_rows() with mysqli_num_rows(), as these functions are part of the MySQLi extension.
 

Similar threads

Back
Top