Try bot

Status
Not open for further replies.
To connect PHP with MySQL, you can use the following steps:

1. Install and configure MySQL server on your system.
2. Install PHP on your system.
3. Install MySQL extension for PHP.
4. Create a new database or use an existing one in MySQL.
5. Create a new user with appropriate privileges for accessing the database.
6. Write PHP code to connect to the MySQL database using the mysqli_connect() function.
7. Execute queries on the MySQL database using PHP.

Here's an example PHP code to connect to a MySQL database:

Code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

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

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

In the above code, replace "localhost" with the hostname or IP address of your MySQL server, "username" and "password" with the credentials of the MySQL user you created, and "database_name" with the name of your database.
 
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database_name"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully"; ?>
Connected successfully
Warning: Undefined array key "username" in C:\xampp\htdocs\inven-it\buy\lg.php on line 6

Fatal error
: Uncaught mysqli_sql_exception: Unknown column 'Designation' in 'field list' in C:\xampp\htdocs\inven-it\buy\lg.php:10 Stack trace: #0 C:\xampp\htdocs\inven-it\buy\lg.php(10): mysqli->prepare('SELECT id, user...') #1 {main} thrown in C:\xampp\htdocs\inven-it\buy\lg.php on line 10
<?php
session_start();
require_once 'conenct.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT id, username, Pass, Fullname, Department, Designation FROM tblaccounts WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $username, $hashed_password, $fullname, $department, $designation);
$stmt->fetch();
if (password_verify($password, $hashed_password)) {
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["fullname"] = $fullname;
$_SESSION["department"] = $department;
$_SESSION["designation"] = $designation;
header("location: index.php");
} else {
echo "Invalid username or password.";
}
} else {
echo "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>

how to fix this error
 
Connected successfully
Warning: Undefined array key "username" in C:\xampp\htdocs\inven-it\buy\lg.php on line 6

Fatal error
: Uncaught mysqli_sql_exception: Unknown column 'Designation' in 'field list' in C:\xampp\htdocs\inven-it\buy\lg.php:10 Stack trace: #0 C:\xampp\htdocs\inven-it\buy\lg.php(10): mysqli->prepare('SELECT id, user...') #1 {main} thrown in C:\xampp\htdocs\inven-it\buy\lg.php on line 10
<?php
session_start();
require_once 'conenct.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT id, username, Pass, Fullname, Department, Designation FROM tblaccounts WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $username, $hashed_password, $fullname, $department, $designation);
$stmt->fetch();
if (password_verify($password, $hashed_password)) {
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["fullname"] = $fullname;
$_SESSION["department"] = $department;
$_SESSION["designation"] = $designation;
header("location: index.php");
} else {
echo "Invalid username or password.";
}
} else {
echo "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>

how to fix this error
The error message "Unknown column 'Designation' in 'field list'" suggests that the column 'Designation' does not exist in the table 'tblaccounts' in your MySQL database.

Make sure that you have spelled the column name correctly and that it exists in the table. Check the spelling and make sure that the column is included in the SQL query that you are using to retrieve data from the table.

Also, the warning "Undefined array key 'username'" suggests that the value of the 'username' key in the $_POST array is not set. Make sure that the 'name' attribute of the username input field in the HTML form matches the 'username' key in the $_POST array in the PHP code.
 
The error message "Unknown column 'Designation' in 'field list'" suggests that the column 'Designation' does not exist in the table 'tblaccounts' in your MySQL database.

Make sure that you have spelled the column name correctly and that it exists in the table. Check the spelling and make sure that the column is included in the SQL query that you are using to retrieve data from the table.

Also, the warning "Undefined array key 'username'" suggests that the value of the 'username' key in the $_POST array is not set. Make sure that the 'name' attribute of the username input field in the HTML form matches the 'username' key in the $_POST array in the PHP code.
how to fix?
 
how to fix?
To fix the "Unknown column 'Designation' in 'field list'" error, you need to ensure that the column named "Designation" exists in the table named "tblaccounts" in your MySQL database. If the column does not exist, you need to add it to the table.

To fix the "Undefined array key 'username'" warning, you need to ensure that the 'name' attribute of the username input field in the HTML form matches the 'username' key in the $_POST array in the PHP code.

For example, if your username input field in the HTML form looks like this:

Code:
<input type="text" name="user" placeholder="Username">

Then you need to change this line in your PHP code:

Code:
$username = $_POST["username"];

to:

Code:
$username = $_POST["user"];

This will ensure that the value of the 'username' key in the $_POST array is set and the warning message is not generated.
 
To fix the "Unknown column 'Designation' in 'field list'" error, you need to ensure that the column named "Designation" exists in the table named "tblaccounts" in your MySQL database. If the column does not exist, you need to add it to the table.

To fix the "Undefined array key 'username'" warning, you need to ensure that the 'name' attribute of the username input field in the HTML form matches the 'username' key in the $_POST array in the PHP code.

For example, if your username input field in the HTML form looks like this:

Code:
<input type="text" name="user" placeholder="Username">

Then you need to change this line in your PHP code:

Code:
$username = $_POST["username"];

to:

Code:
$username = $_POST["user"];

This will ensure that the value of the 'username' key in the $_POST array is set and the warning message is not generated.
Fatal error: Uncaught mysqli_sql_exception: Unknown column 'Designation' in 'field list' in C:\xampp\htdocs\inven-it\buy\lg.php:10 Stack trace: #0 C:\xampp\htdocs\inven-it\buy\lg.php(10): mysqli->prepare('SELECT id, user...') #1 {main} thrown in C:\xampp\htdocs\inven-it\buy\lg.php on line 10
this is the code of in line 10

$stmt = $conn->prepare($sql);

can you fix this?
 
Fatal error: Uncaught mysqli_sql_exception: Unknown column 'Designation' in 'field list' in C:\xampp\htdocs\inven-it\buy\lg.php:10 Stack trace: #0 C:\xampp\htdocs\inven-it\buy\lg.php(10): mysqli->prepare('SELECT id, user...') #1 {main} thrown in C:\xampp\htdocs\inven-it\buy\lg.php on line 10
this is the code of in line 10

$stmt = $conn->prepare($sql);

can you fix this?
The error "Unknown column 'Designation' in 'field list'" is likely caused by the fact that the column named "Designation" does not exist in the table "tblaccounts" in your MySQL database.

To fix this, you will need to add a column named "Designation" to the "tblaccounts" table in your MySQL database. You can do this using SQL by running a query like the following:

Code:
ALTER TABLE tblaccounts ADD Designation VARCHAR(255);

This will add a new column named "Designation" to the "tblaccounts" table with a data type of VARCHAR(255).

Once you have added the column, you should update the SQL query in your PHP code to include the new column. For example:

Code:
$sql = "SELECT id, username, Pass, Fullname, Department, Designation FROM tblaccounts WHERE username = ?";

Make sure that the spelling and case of the column name in the SQL query matches the spelling and case of the column name in the MySQL database.
 
The error "Unknown column 'Designation' in 'field list'" is likely caused by the fact that the column named "Designation" does not exist in the table "tblaccounts" in your MySQL database.

To fix this, you will need to add a column named "Designation" to the "tblaccounts" table in your MySQL database. You can do this using SQL by running a query like the following:

Code:
ALTER TABLE tblaccounts ADD Designation VARCHAR(255);

This will add a new column named "Designation" to the "tblaccounts" table with a data type of VARCHAR(255).

Once you have added the column, you should update the SQL query in your PHP code to include the new column. For example:

Code:
$sql = "SELECT id, username, Pass, Fullname, Department, Designation FROM tblaccounts WHERE username = ?";

Make sure that the spelling and case of the column name in the SQL query matches the spelling and case of the column name in the MySQL database.
here is my code
<?php
session_start();
require_once 'conenct.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["user"];
$Pass = $_POST["Pass"];
$sql = "SELECT id, username, Pass, Fullname, Department, Disgnation FROM tblaccounts WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $username, $Pass, $fullname, $department, $Disgnation);
$stmt->fetch();
if (password_verify($Pass)) {
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["fullname"] = $fullname;
$_SESSION["department"] = $department;
$_SESSION["Disgnation"] = $Disgnation;
header("location: index.php");
} else {
echo "Invalid username or password.";
}
} else {
echo "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>

here is my error
Warning: Undefined array key "Pass" in C:\xampp\htdocs\inven-it\buy\lg.php on line 7

Fatal error
: Uncaught ArgumentCountError: password_verify() expects exactly 2 arguments, 1 given in C:\xampp\htdocs\inven-it\buy\lg.php:19 Stack trace: #0 C:\xampp\htdocs\inven-it\buy\lg.php(19): password_verify(Object(SensitiveParameterValue)) #1 {main} thrown in C:\xampp\htdocs\inven-it\buy\lg.php on line 19

can you fix this?
 
here is my code
<?php
session_start();
require_once 'conenct.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["user"];
$Pass = $_POST["Pass"];
$sql = "SELECT id, username, Pass, Fullname, Department, Disgnation FROM tblaccounts WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $username, $Pass, $fullname, $department, $Disgnation);
$stmt->fetch();
if (password_verify($Pass)) {
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["fullname"] = $fullname;
$_SESSION["department"] = $department;
$_SESSION["Disgnation"] = $Disgnation;
header("location: index.php");
} else {
echo "Invalid username or password.";
}
} else {
echo "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>

here is my error
Warning: Undefined array key "Pass" in C:\xampp\htdocs\inven-it\buy\lg.php on line 7

Fatal error
: Uncaught ArgumentCountError: password_verify() expects exactly 2 arguments, 1 given in C:\xampp\htdocs\inven-it\buy\lg.php:19 Stack trace: #0 C:\xampp\htdocs\inven-it\buy\lg.php(19): password_verify(Object(SensitiveParameterValue)) #1 {main} thrown in C:\xampp\htdocs\inven-it\buy\lg.php on line 19

can you fix this?
The error "Undefined array key 'Pass'" is caused by the fact that the input field in the HTML form is named "password" but you are trying to access it using the key "Pass" in the PHP code. To fix this warning, you should change the following line of code:

Code:
$Pass = $_POST["Pass"];

to:

Code:
$Pass = $_POST["password"];

The error "password_verify() expects exactly 2 arguments, 1 given" is caused by the fact that the password_verify() function requires two arguments: the plain password string and the hashed password string. You are passing only one argument to the function. To fix this error, you should change the following line of code:

Code:
if (password_verify($Pass)) {

to:

Code:
if (password_verify($Pass, $hashed_password)) {

where "$hashed_password" is the hashed password retrieved from the database.

Also, in your SQL query, there is a spelling mistake in the column name "Disgnation". It should be "Designation".
 
The error "Undefined array key 'Pass'" is caused by the fact that the input field in the HTML form is named "password" but you are trying to access it using the key "Pass" in the PHP code. To fix this warning, you should change the following line of code:

Code:
$Pass = $_POST["Pass"];

to:

Code:
$Pass = $_POST["password"];

The error "password_verify() expects exactly 2 arguments, 1 given" is caused by the fact that the password_verify() function requires two arguments: the plain password string and the hashed password string. You are passing only one argument to the function. To fix this error, you should change the following line of code:

Code:
if (password_verify($Pass)) {

to:

Code:
if (password_verify($Pass, $hashed_password)) {

where "$hashed_password" is the hashed password retrieved from the database.

Also, in your SQL query, there is a spelling mistake in the column name "Disgnation". It should be "Designation".
invalid password error
this is my code
<?php
session_start();
require_once 'conenct.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["user"];
$Pass = $_POST["password"];
$sql = "SELECT id, username, Pass, Fullname, Department, Disgnation FROM tblaccounts WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $username, $password, $fullname, $department, $Disgnation);
$stmt->fetch();
if (password_verify($Pass, $password)) {
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["fullname"] = $fullname;
$_SESSION["department"] = $department;
$_SESSION["Disgnation"] = $Disgnation;
header("location: index.php");
} else {
echo "Invalid username or password.";
}
} else {
echo "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>

here are my sql
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- You do not have permission to view the full content of this post. Log in or register now.
--
-- Host: 127.0.0.1
-- Generation Time: Mar 31, 2023 at 07:26 PM
-- Server version: 5.5.8-log
-- PHP Version: 8.2.0
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: dbinventit
--
-- --------------------------------------------------------
--
-- Table structure for table tblaccounts
--
CREATE TABLE tblaccounts (
Id int(11) NOT NULL,
username varchar(255) DEFAULT NULL,
Pass varchar(255) DEFAULT NULL,
Fullname varchar(255) DEFAULT NULL,
Department varchar(255) DEFAULT NULL,
Disgnation varchar(255) DEFAULT NULL,
datecreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table tblaccounts
--
INSERT INTO tblaccounts (Id, username, Pass, Fullname, Department, Disgnation, datecreated) VALUES
(1, 'admin', 'admin', 'Rey Francis', 'Corpalan', 'it', '0000-00-00 00:00:00');
--
-- Indexes for dumped tables
--
--
-- Indexes for table tblaccounts
--
ALTER TABLE tblaccounts
ADD PRIMARY KEY (Id);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table tblaccounts
--
ALTER TABLE tblaccounts
MODIFY Id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

fix it please
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 10
    Replies
  • 468
    Views
  • 1
    Participants
Last reply from:
Exine

Online now

Members online
998
Guests online
1,095
Total visitors
2,093

Forum statistics

Threads
2,276,161
Posts
28,967,972
Members
1,231,145
Latest member
kennethCASTRO2012
Back
Top