Posts

Php mysql

 CREATE DATABASE studentDB; USE studentDB; CREATE TABLE students (   id INT AUTO_INCREMENT PRIMARY KEY,   name VARCHAR(100),   email VARCHAR(100),   age INT,   course VARCHAR(100) ); <?php // Step 1: Connect to MySQL $host = "localhost"; $user = "root"; $pass = ""; // Your MySQL password $db = "studentDB"; $conn = new mysqli($host, $user, $pass, $db); // Check connection if ($conn->connect_error) {   die("Connection failed: " . $conn->connect_error); } // Step 2: Prepare the statement $stmt = $conn->prepare("INSERT INTO students (name, email, age, course) VALUES (?, ?, ?, ?)"); $stmt->bind_param("ssis", $name, $email, $age, $course); // Step 3: Insert 5 records $students = [   ["Adnan", "adnan@example.com", 21, "Computer Science"],   ["Sara", "sara@example.com", 22, "Electronics"],   ["Ravi", "ravi@example.com", 20, "M...

HTML form

 <!DOCTYPE html> <html> <head>   <title>Simple Form</title>   <style>     .error { color: red; font-size: 0.9em; }   </style> </head> <body>   <form onsubmit="return checkForm()">     Name: <input type="text" id="name"><span class="error" id="nameErr"></span><br><br>     Email: <input type="text" id="email"><span class="error" id="emailErr"></span><br><br>     Password: <input type="password" id="pass"><span class="error" id="passErr"></span><br><br>     Confirm Password: <input type="password" id="cpass"><span class="error" id="cpassErr"></span><br><br>     Age: <input type="number" id="age"><span class="err...

CRUD

 <?php $host = "localhost"; $user = "root"; $pass = ""; $db = "crud_db"; $conn = new mysqli($host, $user, $pass, $db); if ($conn->connect_error) {     die("Connection failed: " . $conn->connect_error); } $id = $_GET['id'] ?? null; $action = $_GET['action'] ?? ''; $name = ''; $email = ''; if ($_SERVER["REQUEST_METHOD"] === "POST") {     $name = $_POST['name'];     $email = $_POST['email'];     if ($_POST['action'] === "create") {         $conn->query("INSERT INTO users (name, email) VALUES ('$name', '$email')");     } elseif ($_POST['action'] === "update" && isset($_POST['id'])) {         $id = $_POST['id'];         $conn->query("UPDATE users SET name='$name', email='$email' WHERE id=$id");     }     header("Location: " . $_SERV...

REACT CALCULATOR

 import React, { useState } from 'react'; export default function Calculator() {   const [display, setDisplay] = useState('0');   const [previousValue, setPreviousValue] = useState(null);   const [operation, setOperation] = useState(null);   const [waitingForNewValue, setWaitingForNewValue] = useState(false);   const inputNumber = (num) => {     if (waitingForNewValue) {       setDisplay(String(num));       setWaitingForNewValue(false);     } else {       setDisplay(display === '0' ? String(num) : display + num);     }   };   const inputOperator = (nextOperator) => {     const inputValue = parseFloat(display);     if (previousValue === null) {       setPreviousValue(inputValue);     } else if (operation) {       const newValue = calculate(previousValue, inputValue, operation);       setPrevious...

COMPILER END

 flex example.l gcc lex.yy.c -o lexer -lfl ./lexer example.l example.y bison -d example.y        # generates y.tab.c and y.tab.h flex example.l            # generates lex.yy.c gcc lex.yy.c y.tab.c -o parser -lfl ./parser Q1. Design a LEX Code to count the number of lines, space, tab-meta character, and rest of characters in each Input pattern. Solution: %{ #include<stdio.h> int line = 0 , space = 0 , tab = 0 , meta = 0 , other = 0; %} %% "\n" {line++;} " " {space++;} "\t" {tab++;} [\^\$\%\*\+\-\/\&\(\)\{\}\[\]\;\"] {meta++;} . {other++;} %% int main(){ yylex(); printf("Line:%d\n",line); printf("Space:%d\n",space); printf("Tab:%d\n",tab); printf("Meta:%d\n",meta); printf("Other:%d\n",other); return 0; } int yywrap(){ return 1; } Output: int main(){ cout << "hello"; } Line:3 Space:3 Tab:1 Meta:7 Other:18 Q2. Design a LEX Code to identify and print valid Identifier of C/C++ in gi...