crud operation via php mysql
Important Links
- VLE Insurance Process Flow
- RAP Registration Flow
- RAP and VLE INS POSP
- Life Insurance
- Life Insurance Renewal
- Motor Comprehensive
- Motor Third Party
- Personal Accident
- Fire and Allied Perils
- Health Insurance
- Pradhan Mantri Fasal Bima Yojana (PMFBY)
- NPS
- CSC Digipay Commission Chart
- HDFC Commission
- Axis Bank Commission
- UCO Bank Commission
- ICICI Bank Commission
- BOB Bank Commission
- BOI Bank Commission
- CBI Bank Commission
- LIFE INSURANCE RENEWAL HANDBOOK
- Difference Between CSC RAP Insurance And CSC VLE Insurance - Registration | Products | Commission
- LIC Commission
crud operation via php mysql
CRUD operations (Create, Read, Update, Delete) allow you to interact with a MySQL database using PHP. Here's an example of how you can perform CRUD operations using PHP and MySQL:
- Establish a database connection:
$host = 'localhost';
$dbName = 'your_database_name';
$username = 'your_username';
$password = 'your_password';
$mysqli = new mysqli($host, $username, $password, $dbName);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
exit();
}
Replace 'localhost'
, 'your_database_name'
, 'your_username'
, and 'your_password'
with your actual database credentials.
- Create a new record (Create operation):
$name = 'John Doe';
$email = '[email protected]';
$age = 25;
$query = "INSERT INTO your_table (name, email, age) VALUES ('$name', '$email', '$age')";
$result = $mysqli->query($query);
if ($result) {
echo "Record created successfully.";
} else {
echo "Error: " . $mysqli->error;
}
Replace 'your_table'
with the name of your database table.
- Retrieve records (Read operation):
$query = "SELECT * FROM your_table";
$result = $mysqli->query($query);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "ID: " . $row['id'] . ", Name: " . $row['name'] . ", Email: " . $row['email'] . ", Age: " . $row['age'] . "<br>";
}
} else {
echo "No records found.";
}
This code retrieves all records from the specified table and displays the results.
- Update a record (Update operation):
$id = 1;
$newName = 'Jane Smith';
$query = "UPDATE your_table SET name = '$newName' WHERE id = '$id'";
$result = $mysqli->query($query);
if ($result) {
echo "Record updated successfully.";
} else {
echo "Error: " . $mysqli->error;
}
This code updates the name of the record with the specified ID.
- Delete a record (Delete operation):
$id = 1;
$query = "DELETE FROM your_table WHERE id = '$id'";
$result = $mysqli->query($query);
if ($result) {
echo "Record deleted successfully.";
} else {
echo "Error: " . $mysqli->error;
}
This code deletes the record with the specified ID.
- Close the database connection:
$mysqli->close();
It's important to close the database connection when you're finished with the CRUD operations.
Remember to adjust the code based on your database structure and requirements, including table names and column names. Additionally, consider using prepared statements or input validation to prevent SQL injection attacks.
Latest POst
- LPG Gas Subsidy Check by mobile number
- PMEGP Loan Aadhar Card Se
- E Shram Card Balance Check Number
- How to Migrate CentOS 7 to AlmaLinux 8
- How to Install WHM/cPanel in Almalinux?
- Install cPanel on Rocky Linux 9 Server
- How to Link Aadhaar with UAN
- How To Setup LVS (Linux Virtual Server) Load Balancer on Rocky Linux 8.5
- Setup Quick DNS Server On Rocky Linux 8.5 Using Dnsmasq
- How To Install Ruby on Rails with Mysql on Rocky Linux 8.5
Recent Updates
- LPG Gas Subsidy Check by mobile number
- PMEGP Loan Aadhar Card Se
- E Shram Card Balance Check Number
- How to Migrate CentOS 7 to AlmaLinux 8
- How to Install WHM/cPanel in Almalinux?
- Install cPanel on Rocky Linux 9 Server
- How to Link Aadhaar with UAN
- How To Setup LVS (Linux Virtual Server) Load Balancer on Rocky Linux 8.5
- Setup Quick DNS Server On Rocky Linux 8.5 Using Dnsmasq
- How To Install Ruby on Rails with Mysql on Rocky Linux 8.5
Haryana Goverment Schemes
- Old Age Samman Allowance
- Widow Pension Scheme
- Disability Pension Scheme
- Financial Assistance to Destitute Children Scheme
- Financial Assistance to Non School Going Disabled Children
- Allowance to Dwarfs
- Allowance to Eunuchs
- Rajiv Gandhi Pariwar Bima Yojna
- Post-Matric Scholarship
- Merit Cum Means
- Pre-Matric Scholarship
- About MMPSY
- MMPSY PPT
- MMPSY HINDI Manual
- MMPSY English Manual
- Premium Chart for PMMDY (Pension Plan)
- Parivar Pehchan Patra (PPP)
- Download Family ID
- PMSVANidhi Process Flow
- PM SVANidhi through CSCs
- About PMSYM
- PMSYM Morpho Setting
- PMSYM Creative & FAQ
- PMSYM Process Manual