What's new

Help Pa help sa codes

choiniglory03

Honorary Poster
Established
Joined
Jun 1, 2018
Posts
157
Reaction
454
Points
203
Age
30
Fatal error: Uncaught ArgumentCountError: mysqli_query() expects at least 2 arguments, 1 given in C:\xampp\htdocs\SCESGS\create_account.php:39 Stack trace: #0 C:\xampp\htdocs\SCESGS\create_account.php(39): mysqli_query('INSERT INTO acc...') #1 {main} thrown in C:\xampp\htdocs\SCESGS\create_account.php on line 39

code


if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
echo "<script>alert('PNG, JPG, and JPEG are allowed!')</script>";
} else {
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"], $dir . $_FILES["image"]["name"]);
$query = "INSERT INTO accounts(id,firstname,lastname,username,password,picture,usertype) VALUES (null,'".$firstname."','".$lastname."','".$username."','".$password."','".$picture."','".$usertype."')";
mysql_query($query);
echo "<script>alert('Data Successfully Saved!')</script>";
echo '<script>windows: location="view_accounts.php"</script>';

}
 
The error message you are seeing is a "Fatal error" caused by a missing argument in the mysqli_query() function call on line 39 of your code. The mysqli_query() function requires at least two arguments: the first being the database connection object, and the second being the query you want to execute.

To fix this error, you need to establish a database connection and pass it as the first argument to the mysqli_query() function. Here's an example of how you can modify your code to include the database connection:

PHP:
<?php
// Create a database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check if the connection was successful
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Rest of your code...

if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
    echo "<script>alert('PNG, JPG, and JPEG are allowed!')</script>";
} else {
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name = addslashes($_FILES['image']['name']);
    move_uploaded_file($_FILES["image"]["tmp_name"], $dir . $_FILES["image"]["name"]);
    $query = "INSERT INTO accounts (id, firstname, lastname, username, password, picture, usertype) VALUES (null, '".$firstname."', '".$lastname."', '".$username."', '".$password."', '".$picture."', '".$usertype."')";
    mysqli_query($conn, $query); // Pass the database connection as the first argument
    echo "<script>alert('Data Successfully Saved!')</script>";
    echo '<script>windows: location="view_accounts.php"</script>';
}

// Close the database connection
mysqli_close($conn);
?>

Make sure to replace "localhost", "username", "password", and "database_name" with the appropriate values for your database configuration.

Also note that I have used the mysqli_* functions instead of the deprecated mysql_* functions. It is recommended to use the mysqli_* functions or PDO instead of the mysql_* functions, as they have been removed in newer versions of PHP.
 

Similar threads

Back
Top