如何在mysql数据库中以表格形式输入用户输入的数据

时间:2014-05-17 10:31:28

标签: php

我已经在其中创建了数据库和表。但它显示错误“输入数据失败”

注册表的代码如下 表单代码login2.php:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Form</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
</head>
<body>
<div id="div-regForm">
<div class="form-title" align ="center">VIDEO CHAT </div>
<br></br>
<div class="form-sub-title" align="center">If already registered</div>
<P align="center">
<td><input type="submit" class="blueButton" value="Sign in" align="right"/>
</P>
<br></br>
<div class="form-title">For New User</div>
<div class="form-title">Sign Up</div>
<div class="form-sub-title">It's free and anyone can join</div>

<form id="regForm" action="validate_login.php" method="post">
<table>
<tbody>
<tr>

    <td><label for="fname">First Name:</label></td>
    <td><div class="input-container">
    <input name="fname" id="fname" type="text" />
    </div></td>

</tr>
<tr>

    <td><label for="lname">Last Name:</label></td>
    <td><div class="input-container">
    <input name="lname" id="lname" type="text" />
    </div></td>

</tr>
<tr>

    <td><label for="email">Your Email:</label></td>
    <td><div class="input-container">
    <input name="email" id="email" type="text" />
    </div></td>

</tr>
<tr>

    <td><label for="npass">New Password:</label></td>
    <td><div class="input-container">
    <input name="npass" id="npass" type="password" />
    </div></td>

</tr>
<tr>

    <td><label for="cpass">Confirm Password:</label></td>
    <td><div class="input-container">
    <input name="cpass" id="cpass" type="password" />
    </div></td>

</tr>
<tr>

    <td><label for="sex-select">I am:</label></td>
    <td>
    <div class="input-container">
    <select name="sex-select" id="sex-select">
    <option value="0">Select Sex:</option>
    <option value="1">Female</option>
    <option value="2">Male</option>
    </select>

    </div>
    </td>
</tr>
    <td>

    <div class="input-container">

<tr>

    <td>&nbsp;</td>
    <td><input type="submit" class="greenButton" value="Sign Up"  value="Sent" />
    <img id="loading" src="img/ajax-loader.gif" alt="working.." />
    </td>

</tr>

</tbody>
</table>

</form>

<div id="error">
&nbsp;
</div>

</div>
</body>
</html>

在数据库代码validate_login.php中输入数据:

`

<?php

// Grab User submitted information
$db_host= "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "testdb";

@mysql_connect("$db_host", "$db_user", "$db_pass")
or die("Could not connect to MySQL server!");

/*@mysql_select_db("$db_name") or die("No DATABASE");

echo"hi how r u";*/
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$npass = $_POST["npass"];
$cpass = $_POST["cpass"];
$gender = $_POST["sex-select"];


// Select the database to use
@mysql_select_db("testdb")
or die("Could not select database!");

$order = "Insert INTO 'data_user'
            (fname, lname, email, npass, cpass, sex-select)
            VALUES
            ('$fname',
            '$lname','$email','$npass', '$cpass','$gender')";
            $result = mysql_query($order);  //order executes
if($result){
    echo("<br>Input data is succeed");
} else{
    echo("<br>Input data is fail");
}
?>

尽快告诉我解决方案

1 个答案:

答案 0 :(得分:0)

步骤1:

请将列名更改为sex-select to sex_select

步骤2:

并删除表格中的引号&#39; data_user&#39;到data_user