PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE students ( student_id INT PRIMARY KEY AUTO_INCREMENT, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, age INT, grade DECIMAL(3,2), course VARCHAR(50) ); -- Insert sample data INSERT INTO students (first_name, last_name, age, grade, course) VALUES ('John', 'Doe', 20, 8.5, 'Mathematics'), ('Jane', 'Smith', 19, 9.0, 'Physics'), ('Mike', 'Brown', 21, 7.8, 'Chemistry'), ('Sarah', 'Wilson', 20, 8.9, 'Biology'), ('Tom', 'Davis', 19, 8.2, 'Mathematics'); -- Verify the data SELECT * FROM students;
Copy Clear
Copy Format Clear
<?php // Do NOT create new connection - use the predefined $mysqli variable instead // Prepare the statement $q = mysqli_prepare( $mysqli, "INSERT INTO students (first_name, last_name, age, grade, course) VALUES (?, ?, ?, ?, ?)" ); // Bind the parameters $q->bind_param("ssids", $first_name, $last_name, $age, $grade, $course); // Execute the statement $q->execute(); $result = $mysqli->query("SELECT * FROM students"); // Print the results while ($row = $result->fetch_assoc()) { print_r($row); echo "<br>"; }
Show:  
Copy Clear