當前位置:編程學習大全網 - 腳本源碼 - 留言版代碼

留言版代碼

保存為index.php就行了

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php

if($_REQUEST['action']=='do'){

extract($_POST);

$r=fopen('post.txt','a+');

$str=iconv('utf-8','gb2312',$T1.' '.$R1.' '.$T2.' '.$S1."<br>");

fwrite($r,$str);

echo '<script>location.href="index.php";</script>';

}

if(file_exists('post.txt')){

$result=explode("<br>",substr(iconv('gb2312','utf-8',file_get_contents('post.txt')),0,-4));

foreach ($result as $value){

$arr=explode(" ",$value);

$postarr[]=$arr;

}

}

>

<?php if(count($result)):?>

<?php foreach ($postarr as $value):?>

name:<?php echo $value[0];?><br>

sex:<?php if($value[1])echo 'female';else echo 'male';?><br>

email:<?php echo $value[2];?><br>

message:<?php echo $value[3];?><br>

<hr>

<?php endforeach;?>

<?php else:?>

沒有留言

<?php endif;?>

<form method="post" action="index.php?action=do">

<p>Your name: <input type="text" name="T1"/></p>

<p>Sex:

Male<input type="radio" value="0" name="R1"/>

Female<input type="radio" name="R1" value="1"/></p>

<p>Your email: <input type="text" name="T2" size="35"/></p>

<p>Your massage:</p>

<p> <textarea rows="16" name="S1" cols="44"></textarea></p>

<p><input type="submit" value="Submit" name="B1"/>

<input type="reset" value="Reset" name="B2"/></p>

</form>

</body>

</html>

  • 上一篇:掃壹掃這壹功能使用了什麽識別方法
  • 下一篇:花蝴蝶歌詞
  • copyright 2024編程學習大全網