【发布时间】:2014-11-17 08:14:14
【问题描述】:
我是 PHP 新手。我想通过单击按钮将登录用户的 ID 插入数据库中的另一个表中。任何人都可以指导我完成或回答。
【问题讨论】:
标签: php sql button session-variables submit-button
我是 PHP 新手。我想通过单击按钮将登录用户的 ID 插入数据库中的另一个表中。任何人都可以指导我完成或回答。
【问题讨论】:
标签: php sql button session-variables submit-button
首先你需要你的表格:
<!DOCTYPE html>
<html>
<head>
<title> my title </title>
<meta charset = "utf-8" />
</head>
<body>
<form action = "myfile.php" method = "post">
<input type = "text" placeholder = "id" name = "id" />
<input type = "text" placeholder = "password" name = "password" />
<input type = "submit" />
</form>
</body>
</html>
这只是简单地创建一个表单,其中包含 id 和 pass 的两个输入。
现在你需要写你的myfile.php 告诉它做一个查询:
<?php
$userId = $_POST['id']; // The id is the name of the input
$userPassword = $_POST['password'];
$mytable = "yourTableNameHere"; // You need to create it first with right columns names (in this example, id & pass)
$myServer = "yourServerNameHere"; // localhost by default
$myUserName = "yourUserNameHere"; // name entered to access your database
$myPassword = "yourPassWordHere" // password used to access your database
$myDataBase = "yourDataBaseName";
$myQuery = "INSERT INTO " . $mytable . " (id, pass) VALUES('" . $userId . "', '" . $userPassword . "');";
$mysqli = new mysqli($myServer, $myUserName, $myPassword, $myDataBase);
$mysqli->query($myQuery); // your query is executed here
?>
【讨论】: