MySQL?????????????
?????mengyin ???????[ 2016/9/9 11:07:50 ] ????????????? ???? MySQL
????1.select????????(?????????)
<form name="form1" method="post" action="">
<input name="txt_keyword" type="text" id="txt_keyword" size="40">
<input name="Submit" type="submit" class="btn_grey" value="????" onclick="return check(form)">
</form>
<script type="text/javascript">
function check(form){
if(form.txt_keyword.value==""){
alert("??????????????");
form.txt_keyword.focus();
return false;
}
form.submit(); //?????
}
</script>
<?php
$conn=mysql_connect("localhost"??"root"??"root")or die("????????????".mysql_error()); //?????????
mysql_select_db("testphp"??$conn)or die("???????????".mysql_error()); //????????
mysql_query("set names 'utf8'"); //????????
$keyword=$_POST[txt_keyword]; //????????????
$sql=mysql_query("select * from tb_affiche where title like '%$keyword%' or content like '%$keyword%'"); //??в?????
$row=mysql_fetch_object($sql); //???????????
if(!$row){ //?ж????????????????????????true
echo "<font color='red'>??????????????????</font>";
}
do{ //do...while?????????
?>
<table border="1">
<tr bgcolor="#fffff">
<td width="50" height="31"><?php echo $row->title;?></td>
<td width="433" height="31"><?php echo $row->content;?></td>
</tr>
</table>
<?php
}while ($row=mysql_fetch_object($sql));
mysql_free_result($sql); //???????
mysql_close($conn); // ????????????
?>
????2.insert?????????
add_affiche.php???????
<form name="form1" method="post" action="check_add_affiche.php">
<table width="520" height="212" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="87" align="center">????????</td>
<td width="433" height="31">
<input name="txt_title" type="text" id="txt_title" size="40">*
</td>
</tr>
<tr>
<td width="124" align="center">?????????</td>
<td>
<textarea name="txt_content" cols="50" rows="8" id="txt_content"></textarea>
</td>
</tr>
<tr>
<td height="40" colspan="2" align="center">
<input name="Submit" type="submit" class="btn_grey" value="????" onclick="return check(form)">
<input name="Submit2" type="reset" value="????">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function check(form){
if(form.txt_title.value==""){
alert("???????????");
form.txt_title.focus();
return false;
}
if(form.txt_content.value==""){
alert("?????????????");
form.txt_content.focus();
return false;
}
form.submit();
}
</script>
check_add_affiche.php??????
<?php
$conn=mysql_connect("localhost"??"root"??"root")or die("????????????".mysql_error());
mysql_select_db("testphp"??$conn)or die("???????????".mysql_error());
mysql_query("set names 'utf8'");
$title=$_POST[txt_title];
$content=$_POST[txt_content];
$createtime=date("Y-m-d H:i:s");
$sql=mysql_query("insert into tb_affiche(title??content??createtime)values('$title'??'$content'??'$createtime')");
echo "<script>alert('??????????????');window.location.href='add_affiche.php';</script>";
mysql_free_result($sql);
mysql_close($conn);
?>
????3.update?????????
<?php
$conn=mysql_connect("localhost"??"root"??"root")or die("????????????".mysql_error());
mysql_select_db("testphp"??$conn)or die("???????????".mysql_error());
mysql_query("set names 'utf8'");
$title=$_POST[txt_title];
$content=$_POST[txt_content];
$id=$_POST[id];
$sql=mysql_query("update tb_affiche set title='$title'??content='$content'where id=$id");
if($sql){
echo "<script>alert('??????????????');history??back();window.location.href='modify.php?id=$id';</script>";
}
else{
echo "<script>alert('?????????????');history??back();window.location.href='modify.php?id=$id';</script>";
}
mysql_free_result($sql);
mysql_close($conn);
?>
????4.delete?????????
<?php
$conn=mysql_connect("localhost"??"root"??"root")or die("????????????".mysql_error());
mysql_select_db("testphp"??$conn)or die("???????????".mysql_error());
mysql_query("set names 'utf8'");
$id=$_POST[id];
$sql=mysql_query("delete from tb_addiche where id=$id");
if($sql){
echo "<script>alert('???????????????');history??back();window.location.href='delete_affiche.php?id=$id';</script>";
}
else{
echo "<script>alert('??????????????');history??back();window.location.href='delete_affiche.php?id=$id';</script>";
}
mysql_free_result($sql);
mysql_close($conn);
?>
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11