php+mysql实现简单的增删改查功能

前端之家收集整理的这篇文章主要介绍了php+mysql实现简单的增删改查功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

列表代码

PHP;"> 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 "


<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;"> mysql_select_db("test",$con);

mysql_query("DELETE FROM user WHERE username = '$_POST[username]'");

mysql_close($con);
?>

添加

PHP;"> $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",$con);

mysql_query("UPDATE user SET password = '$_POST[password]' WHERE username = '$_POST[username]'");

mysql_close($con);
?>

@H_403_26@ 用<a href="https://www.jb51.cc/tag/PHP/" target="_blank" class="keywords">PHP</a>向<a href="https://www.jb51.cc/tag/shujuku/" target="_blank" class="keywords">数据库</a>中实现简单的增删改查

Insert:

PHP" method="post"> username: password:


Delete

PHP" method="post"> username:
Are you sure?


Update

PHP" method="post"> username: You want to change your password into:


以上所述就是本文的全部内容了,希望大家能够喜欢。

原文链接:https://www.f2er.com/php/21517.html

猜你在找的PHP相关文章

Username Password