-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit.php
More file actions
82 lines (64 loc) · 2.03 KB
/
edit.php
File metadata and controls
82 lines (64 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
echo 'added new line';//echo $_GET['msg'];
//include basic crud file to access the class
include_once 'basic_crud.php';
//initialize basic crud class object
$crud_object = new Basic_CRUD();
$result = "";
$name_error = "";
$age_error = "";
$msg = "";
$count ="";
//call display method to get the list of all rows in table
if(isset($_GET['id']) && $_GET['id']!="") {
$result = $crud_object->display_crud($_GET['id']);
//var_dump($result);
$count = sizeof($result);
}else{
$msg = "Please send an id";
header("Location:display.php?msg=".$msg);
}
if(isset($_POST['submit']) && $_POST['submit'] = "save") {
//check if both post values(name and age) are set or not empty
if( ($_POST['name']!="") && ($_POST['age'] !="") ) {
var_dump($_POST);
$result = $crud_object->update_CRUD($_POST);
if ($result) {
$msg = "Inserted new data succcessfully.";
header("Location:display.php?msg=".$msg);
}
}else {
//if name is empty set error
if($_POST['name']=="" || !isset($_POST['name'])) {
$name_error = "Name is required.";
}
//if age is empty set error
if($_POST['age']=="" || !isset($_POST['age'])) {
$age_error = "Age is required.";
}
}
}
?>
<?php
if($count>0) {
for($i=0;$i<$count; $i++){
?>
<form name="insert_form" method="post" action="">
<input type='hidden' name='id' value="<?php echo $result[$i]['id']?>">
<table>
<tr>
<td><label>NAME: </label></td>
<td><input type="text" name="name" value="<?php if(isset($_POST['name']) && $_POST['name']!=""){ echo $_POST['name'];} else { echo $result[$i]['name'];}?>"/><?php if(isset($name_error)) echo $name_error;?></td>
</tr>
<tr>
<td><label>AGE: </label></td>
<td><input type="text" name="age" value="<?php if(isset($_POST['age']) && $_POST['age']!=""){ echo $_POST['age'];} else { echo $result[$i]['age'];}?>"/><?php if(isset($age_error)) echo $age_error;?></td>
</tr>
<tr>
<td colspan="2"><label><input type="submit" name="submit" value="Save"> </label></td>
</tr>
</table>
<?php
}//for close
}//if not empty close
?>