用php,mysql注册表单 [英] Register form with php, mysql

查看:95
本文介绍了用php,mysql注册表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的注册表中,所有字段都可以正常工作,但是村庄字段在数据库中返回0.

In my register form all fields work fine, but the village field return a 0 in the database.

我用ajax和jquery为省,地区和村庄创建了一个删除列表.

I used ajax and jquery to create a drop list for governorate and district and village.

前2个工作正常,但村庄没有插入任何东西

The first 2 work fine but the village do not insert anything

我不知道该显示什么代码来使人们理解我,所以我确实显示了整个代码

I didn't know what chunck of code to display to make people understand me so i did display the whole code

这是代码

<?php require_once('for members/scripts/connect.php'); ?>



<?php
function specializationQuery(){

$specData = mysql_query("SELECT * FROM specialization");

  while($recordJob = mysql_fetch_array($specData)){

     echo'<option value="' . $recordJob['specialization_id'] .  '">' . $recordJob['specialization_name'] . '</option>';

  }


}

 //default value
$message = "Fields Marcked with an [*] are Required";
  $username = "";
  $fname = "";
  $lname = "";
  $specialization = "";
  $email = "";
  $pass1 = "";
  $pass2 = "";
  $governorate="";
  $district = "";
  $village = "";

if(isset($_POST['username'])){
  $username = mysql_real_escape_string($_POST['username']);
  $fname = mysql_real_escape_string($_POST['fname']);
  $lname = mysql_real_escape_string($_POST['lname']);
  $email = mysql_real_escape_string($_POST['email']);
  $pass1 = mysql_real_escape_string($_POST['pass1']);
  $pass2 = mysql_real_escape_string($_POST['pass2']);
  $bdate = mysql_real_escape_string($_POST['birthdate']);


  $specialization = mysql_real_escape_string($_POST['specialization']);
  $governorate = mysql_real_escape_string($_POST['governorate']);
  $district = mysql_real_escape_string($_POST['district']);
  $village = mysql_real_escape_string($_POST['village']);

  //error handeling
  if((!$username)||(!$fname)||(!$lname)||(!$email)||(!$pass1)||(!$pass2)||(!$specialization)||(!$governorate)||(!$district)||(!$village)){
  $message = "**** Please insert the Required Fields below ****<br />";

      if($fname == "")
     {
         $message = $message . "Enter First name<br/>";
     }
      if($lname == "")
     {
         $message = $message . "Enter Last name<br/>";
     }

     if( $specialization == 0)
     {
         $message = $message . "Select Your Job<br />";

     }
     if($governorate == 0)
     {
         $message = $message . "Select Your Governorate<br />";
     }

     if($district == 0)
     {
         $message = $message . "Select Your District<br />";
     }
     if($village == "")
     {
     $message = $message . "Select Your Village<br />";

     }
     if($email == "")
     {
         $message = $message . "Enter Email Adress<br/>";
     }
      if ($username == "") {
        $message = $message . "Enter User Name<br/>";
      }

      if($pass1 == "")
     {
         $message = $message . "Enter password<br/>";
     }

      if($pass2 == "")
     {
         $message = $message . "rechek the password <br/>";
     }


 } 

     elseif(strlen($pass1) <= 8)
    {
         $message = $message . "Your Password must be at least 8 charachters<br />";
    }
   else if($pass1!=$pass2){
   $message = "your password do not match!";
 }
 else
 {
   //securing the data
   $username = preg_replace("#[^0-9a-z]#i","",$username);
   $fname = preg_replace("#[^0-9a-z]#i","",$fname);
   $lname = preg_replace("#[^0-9a-z]#i","",$lname);
   //$pass1 = sha1($pass1);

   $email = mysql_real_escape_string($email);
   // checking for duplicate
   $user_query = mysql_query("SELECT user_name FROM user WHERE user_name = '$username'LIMIT 1") or die("could not check the username");
   $count_username = mysql_num_rows($user_query);

    $email_query = mysql_query("SELECT email_address FROM user WHERE email_address = '$email'LIMIT 1") or die("could not check the email");
   $count_email = mysql_num_rows($email_query);

    if($count_username > 0){
     $message = " your username is alredy in use";
    }elseif($count_email > 0){
      $message = "your email is alredy in use";
    }
   else{

      $query = mysql_query("INSERT INTO user(user_name, first_name, last_name, governorate, district, village, birth_date, email_address, specialization, password, registered_date)VALUES('$username', '$fname', '$lname', '$governorate', '$district', '$village', '$bdate', '$email', '$specialization', '$pass1',  now())")or die("could not insert data"); 
      //var_dump($query);


    $message = "you have  now been registered";
    //from the social website


        if ($query) 
       {
       $_SESSION['user_id'] = mysql_insert_id();
       $_SESSION['login'] = 'true';
       $_SESSION['login_user'] = $username;
       }
    /*
    $getid = mysql_fetch_assoc($query);
            //$_SESSION['user_id'] = $getid['user_rid'];
            $_SESSION['user_id'] =mysql_insert_id();
            $_SESSION['login'] = 'true';
            $_SESSION['login_user'] = $getid['username'];
            */


    //header("Location: home.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>Register Page</title>
<link href="style/stylesheet.css" rel="stylesheet" type="text/css" />
<link href="style/imagesGallery.css"rel="stylesheet" type="text/css"/>
<script src="js/main.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript">

 $(document).ready(function(){
                $("select#district").attr("disabled","disabled");
                $("select#village").attr("disabled","disabled");
                $("select#governorate").change(function(){
                $("select#district").attr("disabled","disabled");
                $("select#district").html("<option>wait...</option>");
                var id = $("select#governorate option:selected").attr('value');
                $.post("select_district.php", {id:id}, function(data){
                    $("select#district").removeAttr("disabled");
                    $("select#district").html(data);
                });
            });
            $("select#district").change(function(){ 
            id = $(this).val(); 
            $("select#village").attr("disabled","disabled");
            $("select#village").html("<option>wait...</option>");
            $.post("select_village.php", {id:id}, function(data){


            $("select#village").removeAttr("disabled");
            $("select#village").html(data);
         });
        });
            $("form#registerform").submit(function(){
                var cat = $("select#governorate option:selected").attr('value');
                var type = $("select#district option:selected").attr('value');
                var village = $("select#village option:selected").attr('value');

            });
    });


</script>

</head>

<body>








 <img src="web_header copy.jpg" alt="visitor header" width="1080" height="128" />





       <marquee direction="left" width="99%" behavior="alternate">
        <img src="imggallery/images/akoura/akoura_small.jpg" width="119" height="91">
        <img src="imggallery/images/ballaa2/ballaa2_small.jpg" width="119" height="91">
        <img src="imggallery/images/baalbeck/baalbek_small.jpg" height="92">
        <img src="imggallery/images/barouk/cedre_barouk_small.jpg" width="119" height="91">
        <img src="imggallery/images/batroun/batroun_small.jpg" width="119" height="91">
        <img src="imggallery/images/bchareh/bchareh_small.jpg" width="119" height="91">
        <img src="imggallery/images/beiteldin/beiteldine_small.jpg" width="119" height="91">
        <img src="imggallery/images/beyrouth/beyrouth_small.jpg" width="119" height="91">
        <img src="imggallery/images/beyrouth/beyroyj frm sky/beyrouthfromSky_small.jpg" width="119" height="91">
        <img src="imggallery/images/deir el mara/deirelamar_small.jpg" width="119" height="91">
        </marquee>

        <hr />

       <h2 class="registerTitle">Registration Fields</h2>
       <h4 class="registerTitle">Sign Up Today....</h4>
  <div class="container center"> 


<br />
<br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br />
<p style="color:#FF0000" align="center"><?php print("$message")?></p>



    <?php include "select.class.php"; ?>
    <form id="registerform" action="register.php" method="post">

    first name 
    <input type="text" name="fname" placeholder="Firstname" />
    last name
    <input type="text" name="lname" placeholder="Lastname" />
    <br /> <br />
    Date of Birth
    <input type="date" name="birthdate" value= "YYYY_MM_DD"  onfocus="if (this.value == 'YYYY_MM_DD') {this.value = '';}" onblur="if (this.value == '') {this.value = 'YYYY_MM_DD';}" />
        Specialization:
        <select name="specialization"  class="select">
      <option value="0">-- Select Your Specialization --</option>

        <?php specializationQuery(); ?>
      </select>
        <br /> <br />
        Governorate
        <select id="governorate" name = 'governorate'>
                <?php echo $opt->ShowGovernorate(); ?>
                </select>

      District
      <select id="district" name="district">
                    <option value="0">choose...</option>
                </select>
       Village
       <select id="village" name="village">
                    <option value="0">choose...</option>
                </select>
        <br /> <br />         
       Email:
       <input type="text" name="email" placeholder="Email Adress" />         
       Username:
       <input type="text" name="username" placeholder="Username" />
       <br /><br />  
       Password:
       <input type="password" name="pass1" placeholder="Password" />
       Re_Password:
       <input type="password" name="pass2" placeholder="Validate Password" />
       <br /><br />       
    <input type="submit" value="Register"/>
     </form>
 </div>
</body>
</html>

推荐答案

@ user2326255请检查是否从下拉列表中选择了村庄.在html中,您设置了0选项供选择.如果用户未选择村庄,则将发送默认值.更改代码

@user2326255 Please check that you choose the village from the dropdown list. In the html you have set 0 option for choose. If the user is not select the village then default value will be send. Change the code

if($village == "")
 {
 $message = $message . "Select Your Village<br />";

 }

收件人

if($village == '0')
     {
     $message = $message . "Select Your Village<br />";

     }

如果用户未选择村庄,那么我们需要告诉用户请选择村庄.上面的代码更改将错误提示给用户.

If user does not select the village then we need to tell the user that please select the village. The above code change will throw the error to the user.

这篇关于用php,mysql注册表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆