使用MySQL数据库,我将用户添加到数据库中,如下面的测试数据:
INSERT INTO `database_users`.`Members` (`ID`, `Username`, `Password`,
`First Name`, `Last Name`, `Email Address`, `Telephone Number`,
`Address Line 1`, `Address Line 2`, `Town/City`, `Postcode`,
`Mailing-list`, `Terms`) VALUES (NULL, 'Test', '', '', '', '', '', '',
NULL, '', '', NULL, '');"我的HTML表单如下所示:
<input type="submit" value="Join!">
<div class="col-lg-6">
<input type="text" placeholder="Town/City" id="Town/City">
</div>
<div class="col-lg-6">
<input type="text" placeholder="Postcode" id="Postcode">
</div>
</input>我希望在我的网站上提交表格,并将数据上传到我的MySQL数据库。有人能告诉我表格上遗漏了什么吗?
发布于 2017-03-30 07:35:46
您的sql查询似乎很好,但是如果您不知道如何使用PHP,您会经常被阻塞。
最好的方法是学习基本PHP,知道如何实现注册页面,并在堆栈溢出时询问您在开发过程中是否有问题。
http://www.learn-php.org/
您的表单是不正确的:您需要一个<form>输入,并在其上定义方法(post或get)和操作(数据所在的文件)。
基本上,您的代码必须类似于:
HTML (form.html)
<form method="POST" action="save.php">
<input type="text" name="pseudo">
<input type="submit">
</form>PHP (save.php)
<?php
if(isset($_POST['pseudo'])){ // Test if the variable exists
$pseudo = $_POST['pseudo'];
// Your SQL query here which save the pseudo. Don't forget to test your variables.
}
else {
echo "pseudo is required";
}
?>不要忘记转义变量并使用预先准备好的语句。否则,您的站点将出现许多缺陷,如XSS或SQL注入。
一些链接
与Mysqli一起准备的声明
http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
防止XSS攻击
什么是SQL注入?
http://php.net/manual/en/security.database.sql-injection.php
https://stackoverflow.com/questions/43110594
复制相似问题