æ¹æ³/æ¥éª¤
é¾æ¥æ°æ®åºæ¹æ³ï¼conn.php ã
代ç å¦ä¸ï¼
<?php
$link=mysql_connect('localhost','root','tianqing')or die('æ°æ®åºè¿æ¥é误');
mysql_select_db('studyexam',$link)or die('æ°æ®åºè®¿é®é误');
mysql_query("set names 'utf8'");
?>
å¢å add.php
代ç å¦ä¸:
<?php
include("conn.php");//å¼å
¥é¾æ¥æ°æ®åº
if(!empty($_POST['tj'])){
$title=$_POST['title'];
$con=$_POST['con'];
echo $sql="insert into news(id,title,dates,contents) value (null,'$title',now(),'$con')" ;
mysql_query($sql);
echo"æå
¥æå";
}
?>
<form action="add.php" method="post">
æ é¢: <input type="text" name="title"><br /><br />
å
容: <textarea rows="6" cols="55" name="con"></textarea><hr>
<input type="submit" name="tj" value="æ交">
</form>
å é¤del.php
代ç å¦ä¸ï¼
<?php
include("conn.php");//å¼å
¥é¾æ¥æ°æ®åº<pre name="code" class="html"><?php
include("conn.php");//å¼å
¥é¾æ¥æ°æ®åº
if(!empty ($_GET['id'])){
$sql="select * from news where id='".$_GET['id']."'";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
}
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
$hid=$_POST['hid'];
$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 ";
mysql_query($sql);
echo "<script> alert('æ´æ°æå'); location.href='index.php'</script>";
echo"æ´æ°æå";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']?>"/>
æ é¢: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>
å
容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br>
<input type="submit" name="sub" value="å表">
</form></pre><br>
<?php
if(!empty($_GET['del'])){ $d=$_GET['del']; $sql="delete from news where id ='$d'"; } $query=mysql_query($sql); echo "å é¤æå"; ?><p></p>
<pre></pre>
<br>
æ¹ edit.php页é¢
代ç å¦ä¸ï¼
<?php
include("conn.php");//å¼å
¥é¾æ¥æ°æ®åº
if(!empty ($_GET['id'])){
$sql="select * from news where id='".$_GET['id']."'";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
}
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
$hid=$_POST['hid'];
$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 ";
mysql_query($sql);
echo "<script> alert('æ´æ°æå'); location.href='index.php'</script>";
echo"æ´æ°æå";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']?>"/>
æ é¢: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>
å
容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br>
<input type="submit" name="sub" value="å表">
</form></pre><br>
æ¥è¯¢select.php页é¢
代ç å¦ä¸ï¼
<?php
include("conn.php");
$sql="select * from entries";//entriesè¿æ¯æ°æ®åºåè¯ï¼å¤§å®¶èªå·±æ¹
if($result=mysql_query($sql)){
/*
$num=mysql_num_rows($result)
for($i=1;$i<=$num;$i++);
*/
while($array=mysql_fetch_assoc($result)){
//$biaoti=$array['title'];
$neirong=$array['entry'];
$id=$array['entry_id'];
echo "<p>{$array['title']}</p><p>$neirong</p><p><a href='edit.php?id=$id'>ç¼è¾</a>
<a href='delete.php?id=$id'>å é¤</a></p><hr />";
}
}
?>
温馨提示:答案为网友推荐,仅供参考