由网页提交的表单提交写入数据库 PHP源代码该怎么写
请一个有关php代码的超级简单问题我想将由网页表单提交上来的$username和$password写入用户名密码为$mysql_server_name="localhos...
请一个有关php代码的超级简单问题
我想将 由网页表单提交上来的$username和$password 写入 用户名密码为
$mysql_server_name = "localhost";
$mysql_username = "11111";
$mysql_password = "22222";
$mysql_database = "33333";
的数据库 的player表中的username和password字段中
那我php代码应该怎么写?
我看了很久的教程,都快晕掉了 展开
我想将 由网页表单提交上来的$username和$password 写入 用户名密码为
$mysql_server_name = "localhost";
$mysql_username = "11111";
$mysql_password = "22222";
$mysql_database = "33333";
的数据库 的player表中的username和password字段中
那我php代码应该怎么写?
我看了很久的教程,都快晕掉了 展开
展开全部
把下面的代码保存为post.php
<?
$conn = mysql_connect("localhost","11111","22222");
$action = $_POST['action'];
if($action == 'send'){
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db("333333",$conn);
$sql = "INSERT INTO player (username,password) VALUES ('$username','$password')";
$result = mysql_query($sql,$conn);
}
?>
<html>
<body>
<form method="post" action="post.php">
<input type="text" name="username">
<input type="text" name="password">
<input type="hidden" name="action" value="send">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
<?
$conn = mysql_connect("localhost","11111","22222");
$action = $_POST['action'];
if($action == 'send'){
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db("333333",$conn);
$sql = "INSERT INTO player (username,password) VALUES ('$username','$password')";
$result = mysql_query($sql,$conn);
}
?>
<html>
<body>
<form method="post" action="post.php">
<input type="text" name="username">
<input type="text" name="password">
<input type="hidden" name="action" value="send">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
参考资料: http://bbs.maxkiss.net
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询