当我通过 PHP 表单插入数据时,我成功地将一列添加到 MySQL 的表中,成功添加了电子邮件和密码,但没有添加用户名。
当我显示表格时,“用户名”表格保持空白。
这是 PHP 表单:
<html>
<head>
<title>Register</title>
</head>
<body>
<?php
if(isset($_POST['add']))
{
$dbhost = 'localhost:3036';
$dbuser = 'xxxx';
$dbpass = 'xxxxxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() )
{
$email = addslashes ($_POST['email']);
$password = addslashes ($_POST['password']);
$usernames = addslashes ($_POST['usernames']);
}
else
{
$email = $_POST['email'];
$password = $_POST['password'];
$usernames = $POST['usernames'];
}
$sql = "INSERT INTO users (email,usernames,password) VALUES ('$email', '$usernames', ENCRYPT('$password'))";
mysql_select_db('dbname');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Your Email @foo.com</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td width="100">Your Username</td>
<td><input name="usernames" type="text" id="usernames"></td>
</tr>
<tr>
<td width="100">Your Password</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="add" type="submit" id="add" value="Register">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
我使用命令行添加了用户名列:
ALTER TABLE tbname ADD usernames VARCHAR(55) NOT NULL;
它已添加,但当用户注册时,他的用户名未显示。仅添加电子邮件和加密密码。
任何帮助将不胜感激。