Posts

code

✅ Prerequisites Install: Node.js MySQL Server npm install express mysql2 📁 File Structure /api-mysql |-- server.js |-- db.js |-- routes/ |-- contacts.js |-- books.js |-- notes.js |-- videos.js |-- news.js 🔌 db.js – MySQL Connection const mysql = require('mysql2'); const pool = mysql.createPool({ host: 'localhost', user: 'root', password: 'your_password', database: 'apidb', }); module.exports = pool; 📄 SQL Queries: Create Database & Tables 🚀 Create Database CREATE DATABASE apidb; USE apidb; 16. Contacts Table CREATE TABLE contacts ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), phone VARCHAR(20), email VARCHAR(100) ); 17. Books Table CREATE TABLE books ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100), author VARCHAR(100), availability BOOLEAN DEFAULT TRUE ); 18. Notes Table CREATE TABLE notes ( id INT AUTO_INCREMENT PRIMARY KEY,...

PHP Session Management Program

login.php <?php session_start(); $_SESSION["username"] = "john_doe"; echo "Session started. Welcome, " . $_SESSION["username"]; ?> dashboard.php <?php session_start(); if (isset($_SESSION["username"])) {     echo "Welcome back, " . $_SESSION["username"]; } else {     echo "Please log in first."; } ?> logout.php <?php session_start(); session_unset(); session_destroy(); echo "You have been logged out."; ?>

React App: Product Lookup jsx Copy Edit

 const products = {   '001': { name: 'Laptop', price: '$999', stock: 'In Stock', stores: ['Amazon', 'BestBuy'] },   '002': { name: 'Phone', price: '$499', stock: 'Out of Stock', stores: ['Walmart'] }, }; function ProductLookup() {   const [input, setInput] = useState('');   const [product, setProduct] = useState(null);   const findProduct = () => {     const entry = Object.values(products).find(       p => p.name.toLowerCase() === input.toLowerCase() || input === p.code     );     setProduct(entry);   };   return (     <div>       <h1>Product Lookup</h1>       <input value={input} onChange={(e) => setInput(e.target.value)} placeholder="Enter product code or name" />       <button onClick={findProduct}>Search</button>       {product ? (         <div>     ...

React App: Game Info Lookup

 const games = {   'game1': { title: 'God of War', genre: 'Action', platform: 'PS4', rating: 9.5, year: 2018 },   'game2': { title: 'Halo Infinite', genre: 'FPS', platform: 'Xbox', rating: 8.7, year: 2021 }, }; function GameInfo() {   const [query, setQuery] = useState('');   const [game, setGame] = useState(null);   const searchGame = () => {     const entry = Object.values(games).find(       g => g.title.toLowerCase() === query.toLowerCase() || query === g.id     );     setGame(entry);   };   return (     <div>       <h1>Game Info</h1>       <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Enter game title or ID" />       <button onClick={searchGame}>Search</button>       {game ? (         <div>           <p...

React App: Student Details by ID

 const students = {   '101': { name: 'Alice', class: '10A', marks: 85, status: 'Pass' },   '102': { name: 'Bob', class: '10B', marks: 55, status: 'Pass' },   '103': { name: 'Charlie', class: '10C', marks: 32, status: 'Fail' }, }; function StudentApp() {   const [id, setId] = useState('');   const [student, setStudent] = useState(null);   const fetchStudent = () => {     setStudent(students[id]);   };   return (     <div>       <h1>Student Info</h1>       <input value={id} onChange={(e) => setId(e.target.value)} placeholder="Enter Student ID" />       <button onClick={fetchStudent}>Get Info</button>       {student ? (         <div>           <p>Name: {student.name}</p>           <p>Class: {student.class}</p>     ...

React App: Book Search

 import React, { useState } from 'react'; const dummyBooks = [   { title: "1984", author: "George Orwell", year: 1949, description: "Dystopian novel" },   { title: "Animal Farm", author: "George Orwell", year: 1945, description: "Political allegory" },   { title: "Brave New World", author: "Aldous Huxley", year: 1932, description: "Futuristic society" }, ]; function App() {   const [query, setQuery] = useState('');   const [results, setResults] = useState([]);   const searchBooks = () => {     const filtered = dummyBooks.filter(book =>       book.title.toLowerCase().includes(query.toLowerCase()) ||       book.author.toLowerCase().includes(query.toLowerCase())     );     setResults(filtered);   };   return (     <div>       <h1>Book Search</h1>       <input value={query} onChange={(e) => setQuery(e.target.value)} pl...

CODE

 https://drive.google.com/drive/folders/1El7KyGuCd2XztL-IZxpqRzG93QLvirYV?usp=drive_link