[英]PHP - MYSQL not inserting more than one row
I have my sign up forms in html all setup and working, it runs and inserts a row into mysql table the first time, but I can't insert any more rows. 我在html的所有安装程序和工作程序中都具有我的注册表单,它可以运行并在第一次插入行到mysql表中,但是我无法再插入任何行。
My php is:- 我的PHP是:-
include "config.php";
$gamerid = $_POST['gamerid_create'];
$email = $_POST['email_create'];
$password = md5($_POST['password_create']);
$country = $_POST ['country_create'];
echo "<pre>";
print_r($_POST);
echo "</pre>";
$insert = "insert into users (gamerid,email,password,country) values('$gamerid','$email','$password','$country')";
mysql_query($insert);
Now when I created my table in mysql I used the following code:- 现在,当我在mysql中创建表时,我使用了以下代码:-
CREATE TABLE users
(
id INT primary key NOT NULL AUTO_INCREMENT,
gamerid varchar (255) NOT NULL,
email varchar (255) NOT NULL,
password varchar (255) NOT NULL,
country varchar (255) NOT NULL
)
Why aren't more rows inserted? 为什么不插入更多行?
My html is as follows: 我的HTML如下:
<form id = "signup_form" method = "POST" action = "http://localhost:8080/quizicle/pages/register.php">
<table id = "signup_form_table" border = "0" class = "signup_table_body">
<tr class = "signup_form_tr_label">
<td class = "signup_form_td"><label for "gamerid" class = "signup_form_label">Create a Gamer ID:</label></td>
<td class = "signup_form_td"><label for "email" class = "signup_form_label">Your Email:</label></td>
<td class = "signup_form_td"><label for "password" class = "signup_form_label">Password:</label></td>
<td class = "signup_form_td"><label for "country" class = "signup_form_label">Country:</label></td>
<td class = "signup_form_td"></td>
</tr>
<tr class = "signup_form_tr">
<td class = "signup_form_td"><input type = "text" name = "gamerid_create" id = "gamerid_create" maxlength="50" class = "signup_form_input"/></td>
<td class = "signup_form_td"><input type = "text" name = "email_create" id = "email_create" maxlength="50" class = "signup_form_input"/></td>
<td class = "signup_form_td"><input type = "password" name = "password_create" id = "password_create" maxlength="50" class = "signup_form_input"/></td>
<td class = "signup_form_td">
<select name = "country_create"> <option>Please select a country</option>
<option>United Kingdom</option>
</select>
</td>
<td class = "signup_form_td"><input type = "submit" value = "Sign me up!" id = "btn_register" value = "register" class = "signup_form_submit_btn"/></td>
</tr>
</table>
</form>
<?php
include "config.php";
// INPUT CLEANING FUNCTION
function clean($str)
{
$cleaned = mysql_real_escape_string(strip_tags($str));
return $cleaned;
}
$gamerid = clean($_POST['gamerid_create']);
$email = clean($_POST['email_create']);
$password = clean(md5($_POST['password_create']));
$country = clean($_POST ['country_create']);
$insert = "insert into users(gamerid,email,password,country) values('$gamerid' ,'$email',' $password', '$country')";
mysql_query($insert);
?>
It's probably in regards to your primary key id
这可能与您的主键
id
Let's change up the sql and see if it works. 让我们更改sql,看看它是否有效。
$insert = "INSERT INTO users (id, gamerid, email, password, country)
VALUES (NULL, '{$_POST['gamerid_create']}', '{$_POST['email_create']}',
'{$_POST['password_create']}', '{$_POST['country_create']}');";
Some things you should consider as you develop your skills with PHP / MySQL: 在使用PHP / MySQL开发技能时应考虑的一些事项:
Validate and scrub your user input. 验证并整理您的用户输入。 Sql injection risks.
SQL注入风险。 See: mysql_real_escape_string(), for basic help here.
参见:mysql_real_escape_string(),此处有基本帮助。
You should configure your tables make sure you set the field type and size to the minimum that you need, VARCHAR(255) will waste alot of space if you dont fill it all. 您应该配置表,确保将字段类型和大小设置为所需的最小值,如果不全部填充,VARCHAR(255)将浪费大量空间。
Always hash passwords with at least the md5 algorithm. 始终至少使用md5算法对密码进行哈希处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.