當我通過PHP表單插入數據時,我成功地在MySQL的表中添加了一列,電子郵件和密碼已成功添加,但未添加用戶名。我在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;
據補充,但是當用戶登記,他的用戶名沒有示出。僅添加電子郵件和加密的密碼。
任何幫助將不勝感激。
首先做的事:檢查用戶名是否在INSERT語句中實際存在傾銷,爲一些日誌文件(例如,使用'syslog')。 – arkascha
數據庫中的數據是?我想你只是有一個不好的選擇。 – Vyktor
---評論刪除--- –