php+mysql實(shí)現(xiàn)簡單的增刪改查功能
列表代碼
<?php
$con = mysql_connect("localhost:3306","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM user");
echo "<table border='1'>
<tr>
<th>Username</th>
<th>Password</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
刪除
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
mysql_query("DELETE FROM user WHERE username = '$_POST[username]'");
mysql_close($con);
?>
添加
<?php
$con = mysql_connect("localhost:3306","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql = "INSERT INTO user (username,password)
VALUES
('$_POST[username]','$_POST[password]')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
修改
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
mysql_query("UPDATE user SET password = '$_POST[password]' WHERE username = '$_POST[username]'");
mysql_close($con);
?>
<html>
<head>
<title>用PHP向數(shù)據(jù)庫中實(shí)現(xiàn)簡單的增刪改查</title>
</head>
<body>
<br />
<h1>Insert:</h1>
<form action="insert.php" method="post">
username:<input type="name" name="username"/>
<br />
password:<input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
<br /><hr /><br />
<h1>Delete</h1>
<form action="delete.php" method="post">
username:<input type="name" name="username" />
<br />
Are you sure?<input type="submit" value="sure" />
</form>
<br /><hr /><br />
<h1>Update</h1>
<form action="update.php" method="post">
username:<input type="name" name="username"/>
<br />
You want to change your password into:<input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
<br /><hr /><br />
</body>
</html>
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
PHP反射類ReflectionClass和ReflectionObject的使用方法
PHP反射類ReflectionClass和ReflectionObject2013-11-11
PHP創(chuàng)建XML的方法示例【基于DOMDocument類及SimpleXMLElement類】
這篇文章主要介紹了PHP創(chuàng)建XML的方法,結(jié)合實(shí)例形式分析了php基于DOMDocument類及SimpleXMLElement類創(chuàng)建xml文件的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-09-09
PHP 中檢查或過濾IP地址的實(shí)現(xiàn)代碼
網(wǎng)絡(luò)環(huán)境異常復(fù)雜,有時候我們不得不禁止一些惡意用戶訪問,禁止的方式有很多種,其中一種就是通過 IP 來限制,本文提供的方法允許你通過 IP 區(qū)間、CIDR (Classless Inter-Domain Routing)及單個 IP 格式來檢查或過濾 IP 地址2011-11-11
php通過baihui網(wǎng)API實(shí)現(xiàn)讀取word文檔并展示
這篇文章主要介紹了php通過baihui網(wǎng)API實(shí)現(xiàn)讀取word文檔并展示的相關(guān)資料,需要的朋友可以參考下2015-06-06
使用PHPMailer實(shí)現(xiàn)郵件的實(shí)時發(fā)送功能
這篇文章主要為大家詳細(xì)介紹了如何使用PHPMailer 實(shí)現(xiàn)一個接收詢盤并實(shí)時同步到指定郵箱的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-12-12
PHP實(shí)現(xiàn)找出鏈表中環(huán)的入口節(jié)點(diǎn)
這篇文章主要介紹了PHP實(shí)現(xiàn)找出鏈表中環(huán)的入口節(jié)點(diǎn),涉及php針對環(huán)形鏈表的遍歷、查找、計(jì)算等相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
PHP數(shù)組相加操作及與array_merge的區(qū)別淺析
這篇文章主要給大家介紹了關(guān)于PHP數(shù)組相加操作以及與array_merge的區(qū)別,文中通過示例介紹的很詳細(xì),感興趣的朋友們可以參考學(xué)習(xí),有需要的下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。2016-11-11

