原生态php在html页面读库显库

index.html页面

<html>
<head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312">-->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>input</title>
</head>
<body>
<form method="POST" action="receive.php">
    <p>您的姓名: <input type="text" name="T1" size="20"></p>
    <p>您的性别:男<input type="radio" value="0" name="R1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="R1" value="1"></p>
    <p>您的EMAIL<input type="text" name="T2" size="35"></p>
    <p>您的留言内容:</p>
    <p>&nbsp;<textarea rows="16" name="S1" cols="45"></textarea></p>
    <p> </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="提交" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>

receive.php

<?php
header("content-type:text/html;charset=utf-8");
$user='root';
$password='root';
$db='guestbook';
$table='gbook';

$connect=mysql_connect('localhost',$user,$password); 

if (!$connect) {
    die("Connection failed: " . mysqli_connect_error());

}
$T1=$_POST["T1"];
$R1=$_POST["R1"];
$T2=$_POST["T2"];
$S1=$_POST["S1"];

mysql_select_db("guestbook");
$sql = "INSERT INTO   `guestbook`.`gbook` ( name, sex, email, info) VALUES ('$T1', '$R1', '$T2', '$S1')";
  $result1=mysql_query( $sql);
if(  $result1)
{

//echo"数据插入成功";
$result=mysql_query("select * from $table ");
$arr=mysql_fetch_array($result);
while ($arr=mysql_fetch_array($result))

{
 
       if ($arr[1]==0) 
          {
              $gender='先生';
              $name=$arr[0];
              $info=$arr[3];
              $id=$arr[4];
             
         }
              
      else
          {
              $gender='女人';
              $name=$arr[0];
              $info=$arr[3];
              $id=$arr[4];
          }





}
echo "<table border='1' width ='100%' align=center bgcolor='#FFFFF'>

<tr> <td bordercolor='#FFFFFF' bgcolor='#C0C0C0'>

<p>$name  $gender 写到:</p>
<tr>
<td>&nbsp&nbsp;&nbsp $info</td>
 
    </td> 
    
</tr>
";
echo "</table>";
echo"<a href=\"del.php?id=$id\">[删除]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href=\"modify.php?id=$id\">[修改]</a>]
";

}
else
{
echo"数据插入失败";
}
?>


<!--<html>-->
<!--    <head>-->
<!--          <meta http-equiv="Content-Language" content="zh-cn">-->
<!--          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">-->
<!--        <title>Receive</title>-->
<!--    </head> -->
<!--<body style="background-attachment: fixed">-->
<!--    <table border="1" width="100%" id="table1" bgcolor="#FFFFFF"> -->
<!--<tr> <td >-->
<!--                <p><a href="del.php?id=$id">[删除]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
<!--                    <a href="modify.php?id=$id">[修改]</a>]-->
<!--    </td> -->
<!--</tr>-->
<!--    </table> -->
<!--</body> -->
<!--</html> -->
<?php echo '<p>'; echo '<p>';  ?>
<html>
<head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>返回</title>
</head>
<body>
<p><a href="index.html">&lt;继续留言&gt;</a></p> </body> </html>

del.php

<?php
header("content-type:text/html;charset=utf-8");//防止中文乱码
$id=$_GET['id'];
//echo $id;
//exit;//
$user='root'; $password='root';
$db='guestbook';
$table='gbook';
$sql="DELETE FROM $table WHERE id=$id";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query($sql);
if ($result) echo "数据删除成功";
else echo "数据删除失败"; ?>
<html>
<head>
    <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>删除</title>
</head>
<body>
<p><a href="index.html">继续留言</a></p> </body>
</html> 
modify.php修改
<?php
header("content-type:text/html;charset=utf-8");
$id=$_GET['id'];
$user='root';
$password='root';
$db='guestbook';
$table='gbook';
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query("select * from $table where id=$id");
//if($result)
//{
//    echo"数据查询成功";
//    exit;
//}
$arr=mysql_fetch_array($result);
?>

<html>
<head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>input</title>
</head>
<body>
<form method="POST" action="modify_ok.php?id=<?=$id?>"> <p>您的姓名: <input type="text" name="T1" size="20" value="<?=$arr[0]?>"></p>
    <p>您的性别:
        <?php
        if ($arr[1]==0) echo '<input type="radio" value="0" name="R1" checked>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="R1" value="1"></p>';
        else
            echo '<input type="radio" value="0" name="R1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="R1" value="1" checked></p>'; ?>
    <p>您的EMAIL<input type="text" name="T2" size="35" value="<?=$arr[2]?>"></p>
    <p>您的留言内容:</p> <p>&nbsp;<textarea rows="16" name="S1" cols="45" ><?=$arr[3]?></textarea></p>
    <p> </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="修改" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
修改成功页面
modify_ok.php
<?php
header("content-type:text/html;charset=utf-8");
$id=$_GET['id'];
$user='root';
$password='root';
$db='guestbook';
$table='gbook';
$connect=mysql_connect('localhost',$user,$password);
$T1=$_POST["T1"];
$R1=$_POST["R1"];
$T2=$_POST["T2"];
$S1=$_POST["S1"];
mysql_select_db($db);

$sql = "UPDATE `guestbook`.`gbook` SET `name` = '$T1', `sex` = '$R1', `email` = '$T2', `info` = '$S1' WHERE `gbook`.`id` = '$id' LIMIT 1;";
$result=mysql_query($sql);
if ($result)
    {
        echo "修改成功";
    }
    else
    {
       echo "修改失败";
    }
?>
<html>
<head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>修改成功</title>
</head>
<body>
<p><a href="index.html">&lt;继续留言&gt;</a></p> </body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值