Программа работает бур когда я бегу edit.php это показывает ошибку
view_student.php
<?php require '../mvc/student.php'; $obj = new Student(); $result = $obj->select_all_student(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add student info <table><tbody><tr> <td> <a href="add_student.php">Add student</a> | <a href="view_student.php">View student</a> <h3>All student</h3> </td> </tr> </tbody></table> <?php while($row = $result->fetch_assoc()) { ?> <?php } ?> <table border="1"><tbody><tr> <th>Id</th> <th>Student name</th> <th>Email address</th> <th>Mobile number</th> <th>Action</th> </tr><tr> <td><?php echo $row['student_id'] ?></td> <td><?php echo $row['student_name'] ?></td> <td><?php echo $row['email_address'] ?></td> <td><?php echo $row['mobile_number'] ?></td> <td> <a href="edit.php?id=<?php echo $row['student_id'] ?>">Edit</a> | <a href="delete.php?id=<?php echo $row['student_id'] ?>">Delete</a> </td> </tr></tbody></table>
student.php
<?php class Student { public function __construct() { $hostname = 'localhost'; $username = 'root'; $password = ''; $database = 'db_ci_batch21'; $this->conn = new mysqli($hostname, $username, $password, $database); if(!$this->conn) { die("not connected"); } } public function save_student($data) { $sql = "INSERT INTO tbl_student(student_name, email_address, mobile_number)VALUES('$data[student_name]', '$data[email_address]', '$data[mobile_number]')"; if($this->conn->query($sql)) { $message = "Save data successfully"; return $message; } else { $message = "Data not saved"; return $message; exit; } } public function select_all_student() { $sql = "SELECT * FROM tbl_student"; $result = $this->conn->query($sql); //echo '<pre>'; //print_r($result); //exit; return $result; } public function delete_student($student_id) { $sql = "DELETE FROM tbl_student WHERE student_id = '$student_id'"; $this->conn->query($sql); header('Location: view_student.php'); } public function select_student_info_by_id($student_id) { $sql = "SELECT * FROM tbl_student WHERE student_id = '$student_id' "; $result = $this->conn->query($sql); return $result; } public function update_student($data) { $sql = "UPDATE tbl_student SET student_name='$data[student_name]', email_address='$data[email_address]', mobile_number='$data[mobile_number]' WHERE student_id='$data[student_id]' "; $this->conn->query($sql); header("Location:view_student.php"); } } ?>
edit.php
<?php require '../mvc/student.php'; $obj = new Student(); $student_id = $_GET['id']; $result = $obj->select_student_info_by_id($student_id); $student_info = $result->fetch_assoc(); /*echo '<pre>'; print_r($student_info); exit;*/ if(isset($_POST['btn'])) { $obj->update_student($_POST); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit student info <table><tbody><tr> <td> <a href="add_student.php">Add student</a> | <a href="view_student.php">View student</a> <h3>Edit student</h3> </td> </tr> <tr> <td>Student name</td> <td> </td> </tr> <tr> <td>Email address</td> <td> </td> </tr> <tr> <td>Mobile number</td> <td> </td> </tr> <tr> <td></td> <td> </td> </tr> </tbody></table>
add_student.php
<?php require '../mvc/student.php'; $obj = new Student(); if(isset($_POST['btn'])) { $message = $obj->save_student($_POST); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add student info <h3>Add student</h3> <!-- <h4 style="color: green"> <?php /* if(isset($message)) { echo $message; unset($message); } */?> </h4> --> <table><tbody><tr> <td> <a href="add_student.php">Add student</a> | <a href="view_student.php">View student</a> </td> </tr> <tr> <td>Student name</td> <td> </td> </tr> <tr> <td>Email address</td> <td> </td> </tr> <tr> <td>Mobile number</td> <td> </td> </tr> <tr> <td></td> <td> </td> </tr> </tbody></table>
delete.php
<?php require "../mvc/student.php"; $obj = new Student(); $student_id = $_GET['id']; //echo $student_id; $obj->delete_student($student_id); ?>
когда я запускаю edit.php
это показывает ошибку:
Обратите внимание: неопределенный индекс: id in C:\xampp\htdocs\crud_php\mvc\edit.php на линии 5
Что я уже пробовал:
когда я запускаю edit.php
это показывает ошибку:
Notice: Undefined index: id in C:\xampp\htdocs\crud_php\mvc\edit.php on line 5