fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.09s 54648KB
stdin
<?php
session_start();

/* =====================
   اتصال قاعدة البيانات
===================== */
$conn = mysqli_connect("localhost", "root", "", "student_system");
if (!$conn) {
    die("Database connection failed");
}

/* =====================
   تسجيل الخروج
===================== */
if (isset($_GET['logout'])) {
    session_unset();
    session_destroy();
    header("Location: ?");
    exit;
}

/* =====================
   تسجيل الدخول
===================== */
if (isset($_POST['login'])) {
    $u = mysqli_real_escape_string($conn, $_POST['username']);
    $p = md5($_POST['password']); // (تعمل، لكن غير آمنة مستقبلاً)

    $q = mysqli_query(
        $conn,
        "SELECT * FROM admins WHERE username='$u' AND password='$p'"
    );

    if (mysqli_num_rows($q) === 1) {
        $_SESSION['user'] = $u;
        header("Location: ?");
        exit;
    } else {
        $error = "Login Failed";
    }
}

/* =====================
   إضافة طالب (للمسجلين فقط)
===================== */
if (isset($_SESSION['user']) && isset($_POST['add_student'])) {
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $dep = mysqli_real_escape_string($conn, $_POST['department']);

    mysqli_query(
        $conn,
        "INSERT INTO students (name, email, department)
         VALUES ('$name', '$email', '$dep')"
    );

    header("Location: ?");
    exit;
}

/* =====================
   حذف طالب (للمسجلين فقط)
===================== */
if (isset($_SESSION['user']) && isset($_GET['delete'])) {
    $id = (int) $_GET['delete'];
    mysqli_query($conn, "DELETE FROM students WHERE id=$id");
    header("Location: ?");
    exit;
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Student Management System</title>
</head>
<body>

<h2 style="text-align:center;">Student Management System</h2>
<hr>

<?php if (!isset($_SESSION['user'])) { ?>

    <!-- صفحة تسجيل الدخول -->
    <form method="POST" style="text-align:center;">
        <input type="text" name="username" placeholder="Username" required><br><br>
        <input type="password" name="password" placeholder="Password" required><br><br>
        <button name="login">Login</button>
        <br><br>
        <?php if (isset($error)) echo "<span style='color:red;'>$error</span>"; ?>
    </form>

<?php } else { ?>

    <!-- صفحة النظام -->
    <p>
        Welcome,
        <b><?php echo htmlspecialchars($_SESSION['user']); ?></b>
    </p>

    <h3>Add Student</h3>
    <form method="POST">
        <input type="text" name="name" placeholder="Student Name" required><br><br>
        <input type="email" name="email" placeholder="Email" required><br><br>
        <input type="text" name="department" placeholder="Department" required><br><br>
        <button name="add_student">Add Student</button>
    </form>

    <h3>Students List</h3>
    <table border="1" cellpadding="5">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Department</th>
            <th>Action</th>
        </tr>

        <?php
        $result = mysqli_query($conn, "SELECT * FROM students");
        while ($row = mysqli_fetch_assoc($result)) {
stdout
Standard output is empty