我想用 PHP 制作一个注册表单,将他们的用户名和密码注册到我的 SQL 数据库中。这是我所拥有的:
配置.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);
?>
索引.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 不可用或什么的。等等,让我备份,当我按注册时,它说错误。我将如何解决这个问题?我的编码有什么问题吗?
谢谢,
凯文