Php注册表格不起作用

时间:2015-03-18 15:22:49

标签: php mysql

我已经使用php创建了一个注册表单,但它不起作用,并且它没有显示任何错误。

register.html

<!DOCTYPE html>
<head>
<title>abc</title>
</head> 

<body>

<div class="container">
    <div class="row">
        <div class="col-md-5 col-md-offset-4">
            <div class="panel panel-default">
                <div class="panel-heading"> <strong class="login">Sign Up</strong>

                </div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" name="registration" method="post" action="registration.php">  
                         <!--first name-->
                         <div class="form-group">
                            <label for="fname" class="col-sm-3 control-label">First Name</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="fname" name="fname" placeholder=" First Name" required="">
                            </div>
                        </div>
                        <!--/first name-->
                        <!--last name-->
                         <div class="form-group" >
                            <label for="lname" class="col-sm-3 control-label">Last Name</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="lname" placeholder=" Last Name" required="">
                            </div>
                        </div>
                        <!--/last name-->
                        <!--email-->
                        <div class="form-group">
                            <label for="email" class="col-sm-3 control-label">Email</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="email" name="email" placeholder="Email" required="">
                            </div>
                        </div>
                        <!--email-->
                        <!--Gender-->
                          <div class="form-inline form-group">
                <label class=" col-sm-3 control-label"> Gender</label>
                <label class="male"> &nbsp;&nbsp;
                    <input value="male" type="radio" id="gender" name="male">Male
                </label>
                <label class="female">
                    <input value="female" type="radio" id="gender" name="male">Female
                </label>
                </div>
                        <!--/gender-->
                         <!--address-->
                         <div class="form-group">
                            <label for="address" class="col-sm-3 control-label">Address</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="address" name="address" placeholder=" Address" required="">
                            </div>
                        </div>
                        <!--/address-->
                         <!--telno-->
                         <div class="form-group">
                            <label for="telno" class="col-sm-3 control-label">Contact No</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="telno" placeholder=" Contact No" required="">
                            </div>
                        </div>
                        <!--/telno-->
                        <!--password-->
                       <div class="form-group">
                            <label for="password" class="col-sm-3 control-label">Password</label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control" id="password" name="password" placeholder="Password" required="">
                            </div>
                        </div>
                        <!--password-->
                         <!--password-->
                       <div class="form-group">
                            <label for="repassword" class="col-sm-3 control-label">Re-enter Password</label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control" id="repassword" name="repassword" placeholder="Re-enter Password" required="">
                            </div>
                        </div>
                        <!--password-->
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-9">
                                <div class="checkbox">
                                    <label class="">
                                        <input type="checkbox" class="">Remember me</label> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;     <a href="#"> forget password</a>
                                </div>
                            </div>
                        </div>
                        <div class="form-group last">
                            <div class="col-sm-offset-3 col-sm-9">
                                <button type="submit" class="btn btn-warning btn-sm">Sign Up</button>
                                <button type="reset" class="btn btn-default btn-sm">Reset</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="panel-footer">If you are already Registered? <a href="login.html" class="">LogIn here</a>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>  

这是registration.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php     //start php tag
//include config.php page for database connection
Include('config.php');
//if submit is not blanked i.e. it is clicked.
If(isset($_REQUEST['submit'])!='')
{
   If($_REQUEST['fname']=='' || $_REQUEST['email']=='' || $_REQUEST['password']==''|| $_REQUEST['repassword']=='')
   {
      Echo "please fill the empty field.";
   }
   Else
   {
      $sql="insert into user(firstname,email,password) values('".$_REQUEST['fname']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."')";
      $res=mysql_query($sql);
      If($res)
      {
         Echo "Record successfully inserted";
      }
      Else
      {
         Echo "There is some problem in inserting record";
      }
   }
}
?>
</body>
</html>

这是config.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$hostname="localhost"; //local server name default localhost
$username="root";  //mysql username default is root.
$password="";       //blank if no password is set for mysql.
$database="rcjcompany";  //database name which you created
$con=mysql_connect($hostname,$username,$password);
if(! $con)
{
   die('Connection Failed'.mysql_error());
}

mysql_select_db($database,$con);
?>
</body>
</html>

这是数据库的SQL

创建数据库学生; 使用学生; create table student(id int,name varchar(40),email varchar(80),password varchar(40));

1 个答案:

答案 0 :(得分:0)

如果您没有任何名为&#34;提交&#34;的字段,那么第一个似乎毫无用处。我使用你的代码并使用firefox进行调试,你可以看到没有名为submit的字段发送到服务器:

Firefox Debug

尝试删除第一个if或添加else条件,这样至少可以获得任何打印。

相关问题