<?php include 'register.php';?><!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><linkrel="stylesheet"href="styles.css"><!-- Make sure to link your CSS file --><title>User Registration</title></head><body><div><h1>User Registration Form</h1><formaction="register.php"method="POST"><inputtype="text"name="Firstname"placeholder="Firstname"><br><br><inputtype="text"name="Lastname"placeholder="Lastname"><br><br><inputtype="number"name="Age"placeholder="Age"><br><br><inputtype="submit"name="save_btn"value="Save Data"><!-- Name attribute added --></form></div><?php
// Ensure this script runs only when the form is submittedif(isset($_POST['save_btn'])){// Assuming $connect is your database connection object
include 'register.php';// Include your database connection file// Sanitize user inputs (consider using prepared statements for better security)
$fname = mysqli_real_escape_string($connect, $_POST['Firstname']);
$lname = mysqli_real_escape_string($connect, $_POST['Lastname']);
$age = mysqli_real_escape_string($connect, $_POST['Age']);// SQL query to insert data into your database
$query ="INSERT INTO students (Firstname, Lastname, Age) VALUES ('$fname', '$lname', '$age')";// Execute the query
$result = mysqli_query($connect, $query);if($result){
echo "Record inserted successfully!";}else{
echo "Error: ". mysqli_error($connect);}// Close the database connection
mysqli_close($connect);}?></body></html>
تم التعديل في بواسطة Mustafa Suleiman تعديل عنوان السؤال وتنسيق الكود
السؤال
Ahmed Elshaikh
database تعرض البيانات فارغة والكود ادناه :
تعديل عنوان السؤال وتنسيق الكود
1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.