4

我的 $_POST 正在接收用户名和密码,但没有收到我拥有的任何其他条款。这些名称都与我的表中的名称相匹配,我一定遗漏了一些东西。首先是我的带有表单数据的 HTML 文件,其次是应该将值存储在我的 user_info 表中的 php 文件。

<HTML>
<link rel="stylesheet" href="testcss.css" type="text/css">
<body>

<div id="header">
<h1>Register</h1>
</div>

<div id="formtext">
    <form name="register" action="register.php" method="post">
    First Name: <input type:"text" name"firstName"><br>
    Last Name: <input type"text" name"lastName"><br>
    Email: <input type:"text" name"email"><br>
    Desired Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" name="Submit">
</div>

</body>
</HTML>

这是php文件...

<?php
mysql_connect('localhost', 'root', 'root') or die(mysql_error());
mysql_select_db("myDatabase") or die(mysql_error());

$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$username = $_POST["username"];
$password = $_POST["password"];


mysql_query("INSERT INTO user_info(firstName, lastName, email, username, password) VALUES ('$firstName', '$lastName', '$email', '$username', '$password')");

header( 'Location: loaclhost:8888/userHome.html' ) ;

?>
4

2 回答 2

7

您的 HTML 属性格式不正确。

所有属性都应采用格式attribute="value"

两个工作的格式正确,而其他的则没有。

例如,<input type:"text" name"email">是错误的。它应该是<input type="text" name="email" />

它们应该是这样的:

    First Name: <input type="text" name="firstName"><br>
    Last Name: <input type="text" name="lastName"><br>
    Email: <input type="text" name="email"><br>
    Desired Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" name="Submit">

如果您还没有使用,我建议您使用具有语法突出显示或自动完成功能的代码编辑器。Notepad++、Netbeans 或 Visual Studio 都可以为您的代码着色并更容易发现错误。

您的 PHP 中可能还有一个错误:header( 'Location: loaclhost:8888/userHome.html' ) ;-我有一种感觉,您可能打算在那里键入“localhost”;-)

于 2012-11-24T04:03:25.943 回答
3

您的标记有几个错误:

<input type:"text" name="" />
<input type"text" name="" />

应该

<input type="text" name="" />
于 2012-11-24T04:03:21.573 回答