我的表单不会将插入的数据发布到我的数据库中,我知道这是一个非常基本的问题,但我只是开始学习编码
connect_to_mysql.php:
<?php
$db_host="localhost";
$db_username="ajamesbird";
$db_pass="";
$db_name="test";
$db_connect = mysql_connect("$db_host","$db_username","$db_pass")or die
("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");
?>
的login.php
<html>
<?php include "C:\Users\andrew\Documents\Websites\Seller\storescripts\connect_to_mysql.php";?>
<?php
if(isset($_POST['loginform'])){
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$sql = ("INSERT INTO users (id, access_level, username, firstname,
lastname, email, password, dob, date_added, activated)
VALUES ('NULL','NULL','$username','$firstname','$lastname','$email', '$password', '$dob', now(), '0')") or die (mysql_error());
if(!mysql_query($db_connect, $sql)){
die('Error inserting into database');
}
}
?>
<head>
<link href="style/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="login.php" enctype="multipart/form-data" name="loginform" id="loginform" method="post">
<input name="username" type="text" id="username" size="63" class="form-control" value="Username" required/>
<input name="firstname" type="text" id="firstname" size="63" class="form-control" value="First name" required/>
<input name="lastname" type="text" id="lastname" size="63" class="form-control" value="Last name" required/>
<input name="email" type="email" id="email" size="63" class="form-control" value="Email" required/>
<input name="password" type="password" id="password" size="63" class="form-control" value="Password" required/>
<input name="dob" type="text" id="dob" size="63" class="form-control" value="Date of Birth" required/>
<input type="submit" name="button" id="button" size="64" value="Sign Up" />
</form>
</body>
</html>
提前谢谢
答案 0 :(得分:0)
尝试移动name =“loginform”并将其放入隐藏输入
<html>
<?php include "C:\Users\andrew\Documents\Websites\Seller\storescripts\connect_to_mysql.php";?>
<?php
if(isset($_POST['loginform'])){
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$sql = ("INSERT INTO users (id, access_level, username, firstname,
lastname, email, password, dob, date_added, activated)
VALUES ('NULL','NULL','$username','$firstname','$lastname','$email', '$password', '$dob', now(), '0')") or die (mysql_error());
if(!mysql_query($db_connect, $sql)){
die('Error inserting into database');
}
}
?>
<head>
<link href="style/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="login.php" enctype="multipart/form-data" method="post">
<input name="username" type="text" id="username" size="63" class="form-control" value="Username" required/>
<input name="firstname" type="text" id="firstname" size="63" class="form-control" value="First name" required/>
<input name="lastname" type="text" id="lastname" size="63" class="form-control" value="Last name" required/>
<input name="email" type="email" id="email" size="63" class="form-control" value="Email" required/>
<input name="password" type="password" id="password" size="63" class="form-control" value="Password" required/>
<input name="dob" type="text" id="dob" size="63" class="form-control" value="Date of Birth" required/>
<input type="submit" name="button" id="button" size="64" value="Sign Up" />
<input type="hidden" name="loginform">
</form>
</body>
</html>