尽管代码正常工作,但数据不会保存到数据库中

时间:2016-01-16 21:20:45

标签: php html database

我试图将用户注册到数据库中。代码正常工作但数据最终没有保存到数据库中。最终输出为“您已成功注册!管理员确认无需”应该是。这是我的报名表:

<html >
<head>
<title></title>
</head>
<body>
<?php
print ("<form action='register.php' method='post'>
    <p>Name
        <input type='text' name='firstname'  />
    </p>
    <p>Surname
        <input type='text' name='lastname' />
    </p>
    <p>Username
        <input type='text' name='username' />
    </p>
    <p>Password
        <input type='password' name='password' />
        </p>
        <p>Email <input type='text' name='email'/>  </p>
      Enter your CV: <p> <textarea name='cv' cols='60' rows='50'></textarea> </p>

      
    
  <input type='submit'  value='Register'/>  
</form>

        ");



if( !($database=mysql_connect("localhost","root",""))||!(mysql_select_db("st_login",$database))  )
   print("Could not connect");

if(isset($_POST['firstname'] )&&isset($_POST['lastname'])&&isset($_POST['username'])&&isset($_POST['password'])
  &&isset($_POST['cv'])/*&&isset($_POST['notat'])&&isset($_POST['lendet'])*/&&isset($_POST['email'])){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$username=$_POST['username'];
$password=md5($_POST['password']);
$email=$_POST['email'];

$cv=$_POST['cv'];
/*
$notat=$_POST['notat'];
$lendet=$_POST['lendet'];
*/

$query = "INSERT INTO  login (firstname, lastname, username,password,cv,email,admin,approval) VALUES ('$firstname', '$lastname',
 '$username','$password','$cv','$email',0,0)";
}
if ( !empty($firstname)&&!empty($lastname)&&!empty($username) &&!empty($password)&&!empty($cv)&&!empty($email))
{
  if(!($result=mysql_query($query,$database)))
{
    print("Could not execute query");
    die (mysql_error());//ose error
}
echo "YOU HAVE BEEN REGISTERED SUCCESSFULLY!PLEASE WAIT FOR THE ADMIN APPROVAL!";

}
else echo "Fill in all the blank fields";
mysql_close($database);
?>

</body>
</html>

这是我的数据库:The database

2 个答案:

答案 0 :(得分:1)

phpMyAdmin通常需要刷新才能看到更新的数据。 点击重新加载或点击其他地方然后返回以显示新数据。

答案 1 :(得分:0)

好吧,除了使用mysql_connect而不是mysqli或预处理语句之外,调试此类问题的最简单方法是回显查询并尝试在phpMyAdmin或您喜欢的mysql客户端中运行它。