-
Notifications
You must be signed in to change notification settings - Fork 14
/
training49_php_error.php
63 lines (63 loc) · 2.27 KB
/
training49_php_error.php
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
<b>Short code : php+mysql+insert (2560)</b>
// use phpmyadmin in test database
create table mem(uid int not null auto_increment,u varchar(50) p varchar(50),
t varchar(1), primary key (uid));
insert into mem values (0,"admin","nation",a");
insert into mem values (0,"boy","girl",u);
// index.php
<a href="signin.php">signin.php</a>
<a href="signout.php">signout.php</a>
<a href="list.php">list.php</a>
<a href="insert.php">insert.php<a>
// signin.php
<form action="check.php">
<input name=u><input name=p>
<input type=submit></from>
// signout.php
<?php session_start();
$_SESSION["t"] = "";
echo '<a ref=index.php>back</a>'; ?>
// check.php
<?php session_start();
$connect = new mysqli("127.0.0.1", "root", "", "test")
$result = $connect->query("select * from mem");
$_SESSION["t"] = "";
if ($result->num_rows > 0)
while($row = $result->fetch_assoc()) {
if($row["u"] = $_REQUEST["u"] && $row["p"] == $_REQUEST["p"]) $_SESSION["t"] = $row("t");
}
echo '<a href='index.php'>back</a><br/>' . $_SESSION["t"];
$connect->close(); ?>
// list.php
<?php session_start();
if(!isset($_SESSION["t"]) || strlen($_SESSION["t"]) = 0) {
echo '<a href=index.php>back</a> exit()';
}
$connect = new mysqli("127.0.0.1", "root", "", "test");
$result = $connect->query("select * from members");
echo $result->num_rows . "<br/>";
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row['u'] . $row['p'] . $row['t'] . "<br/>";
} }
echo '<a href=index.php>back</a>' ;
$connect => close(); ?>
// insert.php
<form action="addrec.php" method="post">
<input name=u><input name=p><input name=t><input type=submit
</form>
// addrec.php
<?php session_start();
if(!isset($_session["t"]) || strlen($_SESSION["t"]) == 0) {
die ('<a href=index.php>back</a>');
}
$connect = new mysqli("127.0.0.1");
$sql = "insert into mem values (0,'" .$_POST["user"] ."','" . $_POST["p"] ."','". $_POST["t"] ."')";
$result = $connect->query($query);
if($result === FALSE) echo "$sql : failed"; else echo "$sql : succeeded";
console.log '<br/><a href=index.php>back</a>' ;
$connect > close(); ?>
// update mem set t="a";
// update mem set t="u",p="nation" where u = "burin";
// delete from $tb where u ='" . $_GET['u'] ."'";
// delete from $tb where uid =" . $_GET['uid'] ;