Short code : php+mysql+insert (2560)
// 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></form>
// signout.php
<?php session_start();
$_SESSION["t"] = "";
echo '<a href=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 mem");
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", "root", "", "test");
$sql = "insert into mem values (0,'". $_POST["u"] ."','" . $_POST["p"] ."','". $_POST["t"] ."')";
$result = $connect->query($sql);
if($result === FALSE) echo "$sql : failed"; else echo "$sql : succeeded";
echo '<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'] ;