我想從PHP製作一個註冊表單,將他們的用戶名和密碼註冊到我的SQL數據庫中。以下是我有:PHP註冊表 - SQL
的config.php:
<?php
$host['naam'] = 'localhost'; // my host
$host['gebruikersnaam'] = 'root'; // my database username
$host['wachtwoord'] = ''; // my database password
$host['databasenaam'] = 'project'; // my database name
$db = mysql_connect($host['naam'], $host['gebruikersnaam'], $host['wachtwoord']) OR die ('Cant connect to the database');
mysql_select_db($host['databasenaam'], $db);
?>
的index.php:
<head>
<title>Deltalus Account Registration</title>
<style>
*{ FONT-SIZE: 8pt; FONT-FAMILY: verdana; } b { FONT-WEIGHT: bold; } .listtitle { BACKGROUND: #425984; COLOR: #EEEEEE; white-space: nowrap; } td.list { BACKGROUND: #EEEEEE; white-space: nowrap; } </style>
</head>
<center><br><br><br><br>
<h1>Deltalus Database</h1>
<table cellspacing=1 cellpadding=5>
<tr>
<td class=listtitle colspan=2>Register at my server</td></tr>
<form action="register_do.php" method="POST">
<tr><td class=list align=right>Username:</td><td class=list><input type=text name=name maxlength="30"></td></tr>
<tr><td class=list align=right>Password:</td><td class=list><input type=password name=pass maxlength="30"></td></tr>
</td></tr>
<tr><td class=listtitle align=right colspan=2><input type=submit name=submit value='Register'></td></tr>
</form>
</table>
<br>
</center></body></html
>
register_do.php:
<?php
print '<title>Deltalus Database Server</title>';
$name = $_POST['name'];
$pass = $_POST['pass'];
include('config.php');
$sel = 'SELECT * FROM user WHERE username="'.$_POST['name'].'"';
if($name == ""){
echo 'No username filled in';
exit();
}elseif(mysql_num_rows(mysql_query($sel)) >= 1){
echo 'This username does already exists!';
exit();
}elseif($pass == ""){
echo 'No password filled in';
exit();
}else{
$d = 'INSERT INTO users (username, password) VALUES ("'.$name.'", "'.$pass.'")';
mysql_query($d) OR die (mysql_error());
echo 'Your account has been created, you can now login.';
}
?>
好了,所以是問題,當我發佈到我的網站。它給了我這個錯誤,說POST不可用或者什麼。等待讓我備份,當我按下注冊表時,它說錯誤。我將如何解決這個問題?他們的編碼有什麼問題嗎?
感謝,
凱文
「POST不可用或某事」是問題的最重要部分。如果您僅發佈了確切的錯誤消息,而沒有其他信息,那麼比發佈整個源代碼更容易幫助您。 – 2009-10-24 18:13:15
我是否看到SQL注入漏洞? – ZippyV 2009-10-24 18:17:08