6、input.php(插入留言)
<?php require_once("conn.php");
$username = $_POST['name']; $sex = $_POST['sex']; $qq = $_POST['qq']; $email = $_POST['email']; $info = $_POST['info'];
if (strrpos($username,"<")!==false || strrpos($username,">")!==false||strrpos($username,"@")!==false||strrpos($username,"\"")!==false||strrpos($username,"'")!==false||strrpos($username,"_")!==false) { echo "<script>alert('名稱不能有特殊字符!');location.href='post.php';</script>"; exit(); }
if (!ereg("^[0-9]{0,}$",$qq))//用正則檢查QQ格式 { echo "<script>alert('OICQ信息有錯(cuò)誤!必須是數(shù)字!');location.href='post.php';</script>"; exit(); }
if($email) {//如果填寫了郵箱就用正則檢查郵箱格式 if (!ereg("^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",$email)) { echo "<script>alert('email格式不正確!');location.href='post.php';</script>"; exit(); } }
if(!$username) { echo "<script>alert('名稱不能為空哦!');location.href='post.php';</script>"; exit(); } elseif(!$info) { echo "<script>alert('留言不能為空哦!');location.href='post.php';</script>"; exit(); } else { $ip = getenv('REMOTE_ADDR');//獲取客戶端IP地址
$sql = "insert into lo (username,sex,qq,email,info,ip,submit_time) values ('$username','$sex','$qq','$email','$info','$ip',NOW())";
$result = mysql_query($sql);
mysql_close();
echo "<script>alert('提交成功!返回首頁(yè)');location.href='index.php';</script>"; } ?>
7、update.php(修改留言頁(yè))
<?php session_start(); require_once('conn.php'); require_once('header.php');
if($_SESSION["key"]==1) { $id = $_GET['id']; $sql = "select * from lo where id= ".$id; $result = mysql_query($sql); $row = mysql_fetch_array($result);
?>
<div id="update"> <form action="updatepost.php?wuleying&id=<?= $row[0] ?>" method="post"> <h1>修改留言</h1> <p>姓名:<input type="text" value="<?= $row[1]?>" name="name" class="y"></input></p> <p>留言:</p> <p><textarea name="info" rows="5" cols="35"><?= $row[5] ?></textarea></p> <p class="cen"><input type="submit" value="偶要修改" /></p> <p class="cen1">銀子留言板 Version 1.0</p> </form>
<div>
<?php } else { header('location:index.php'); } ?>
出處:藍(lán)色理想
責(zé)任編輯:blue
上一頁(yè) 打造簡(jiǎn)單的PHP&MYSQL留言板 [2] 下一頁(yè) 打造簡(jiǎn)單的PHP&MYSQL留言板 [4]
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
|