Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.96 KB | None | 0 0
  1. <?php
  2. session_start();                                          
  3. switch (@$_POST['Button'])                                
  4. {
  5.   case "Log in":                                        
  6.   include("rmb.php");                                
  7.     $cxn = mysqli_connect($host,$user,$password,$dbase)
  8.              or die("Query died: connect");              
  9.     $sql = "SELECT username FROM user
  10.              WHERE username='$_POST[fusername]'";
  11.     $result = mysqli_query($cxn,$sql)
  12.                 or die("Query died: fusername ");
  13.                 //.mysqli_error($cxn));
  14.     $num = mysqli_num_rows($result);                    
  15.     if($num > 0)  //login name was found                
  16.     {
  17.       $sql = "SELECT username FROM user
  18.              WHERE username='$_POST[fusername]'
  19.              AND password='$_POST[fpassword]'";
  20.       $result2 = mysqli_query($cxn,$sql)
  21.                    or die("Query died: fpassword");      
  22.       $num2 = mysqli_num_rows($result2);                
  23.     @h@  if($num2 > 0)  //password matches                  
  24.       {
  25.         $_SESSION['auth']="yes";                        
  26.         $_SESSION['logname'] = $_POST['fusername'];      
  27.         $sql = "INSERT INTO login (username,logintime)
  28.                VALUES ($_SESSION[logname],NOW())";
  29.         $result = mysqli_query($cxn,$sql)
  30.                    or die("query died: insert");      
  31.         header("Location: home.php");  
  32.       }@h@
  33.       else  // password does not match    
  34.         {
  35.         $message_1="The Login Name, '$_POST[fusername]'
  36.                exists, but you have not entered the
  37.                correct password! Please try again.";
  38.         $fusername = strip_tags(trim($_POST['fusername']));
  39.         include("form.php");
  40.       }                                                
  41.     }                                                  
  42.     else  // login name not found                    
  43.     {
  44.       $message_1 = "The User Name you entered does not
  45.                    exist! Please try again.";
  46.       include("form.php");
  47.     }
  48.   break;                                                
  49.  
  50.   case "Register":                                      
  51.    /* Check for blanks */
  52.     foreach($_POST as $field => $value)                
  53.     {
  54.         if(empty($value))
  55.         {
  56.           $blanks[] = $field;
  57.         }
  58.         else
  59.         {
  60.           $good_data[$field] = strip_tags(trim($value));
  61.         }
  62.     }                                                  
  63.     if(isset($blanks))                                  
  64.     {
  65.       $message_2 = "The following fields are blank.
  66.            Please enter the required information:  ";
  67.       foreach($blanks as $value)
  68.       {
  69.         $message_2 .="$value, ";
  70.       }
  71.       extract($good_data);                            
  72.       include("form.php");
  73.       exit();                                          
  74.     }                                                  
  75.   /* validate data */
  76.     foreach($_POST as $field => $value)              
  77.     {
  78.       if(!empty($value))                            
  79.       {
  80.         if(preg_match("/name/i",$field) and
  81.           !preg_match("/user/i",$field) and
  82.           !preg_match("/log/i",$field))
  83.         {
  84.           if (!preg_match("/^[A-Za-z' -]{1,50}$/",$value))
  85.           {
  86.              $errors[] = "$value is not a valid name. ";
  87.           }
  88.         }
  89.         if(preg_match("/street/i",$field) or
  90.            preg_match("/addr/i",$field) or
  91.            preg_match("/city/i",$field))
  92.         {
  93.           if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/",
  94.                           $value))
  95.           {
  96.             $errors[] = "$value is not a valid address
  97.                          or city.";
  98.           }
  99.         }
  100.         if(preg_match("/state/i",$field))
  101.         {
  102.           if(!preg_match("/^[A-Z][A-Z]$/",$value))
  103.           {
  104.             $errors[] = "$value is not a valid state code.";
  105.           }
  106.         }
  107.         if(preg_match("/email/i",$field))
  108.         {
  109.           if(!preg_match("/^.+@.+\\..+$/",$value))
  110.           {
  111.             $errors[]="$value is not a valid email address.";
  112.           }
  113.         }
  114.         if(preg_match("/zip/i",$field))
  115.         {
  116.           if(!preg_match("/^[0-9]{5}(\-[0-9]{4})?$/",$value))
  117.           {
  118.             $errors[] = "$value is not a valid zipcode. ";
  119.           }
  120.         }
  121.         if(preg_match("/phone/i",$field) or
  122.            preg_match("/fax/i",$field))
  123.         {
  124.           if(!preg_match("/^[0-9)(xX -]{7,20}$/",$value))
  125.           {
  126.             $errors[]="$value is not a valid phone number.";
  127.           }
  128.         }
  129.       } // end if not empty                            
  130.     }
  131.     foreach($_POST as $field => $value)                
  132.     {
  133.       $$field = strip_tags(trim($value));
  134.     }
  135.     if(@is_array($errors))                        
  136.     {
  137.       $message_2 = "";
  138.       foreach($errors as $value)
  139.       {
  140.         $message_2 .= $value." Please try again<br />";
  141.       }
  142.       include("form.php");
  143.       exit();
  144.     } // end if errors are found                    
  145.  
  146.    /* check to see if user name already exists */
  147.     include("rmb.php");                            
  148.     $cxn = mysqli_connect($host,$user,$password,$dbase)
  149.              or die("Couldn't connect to server");
  150.     $sql = "SELECT username FROM user
  151.                WHERE username='$username'";      
  152.     $result = mysqli_query($cxn,$sql)
  153.                 or die("Query died: username.");
  154.     $num = mysqli_num_rows($result);                    
  155.     if($num > 0)                                      
  156.     {
  157.       $message_2 = "$username already used. Select
  158.                       another User Name.";
  159.       include("form.php");
  160.       exit();
  161.     } // end if user name already exists
  162.     else // Add new user to database              
  163.     {  
  164.       $sql = "INSERT INTO user (username,createDate,
  165.                password,firstName,lastName,street,city,
  166.                state,zip,phone,fax,email) VALUES
  167.              ('$username',NOW(),md5('$password'),
  168.               '$firstName', '$lastName','$street','$city',
  169.               '$state','$zip','$phone','$fax','$email')";
  170.       mysqli_query($cxn,$sql);                        
  171.       $_SESSION['auth']="yes";                        
  172.       $_SESSION['logname'] = $username;              
  173.       /* send email to new Customer */
  174.       $emess = "You have successfully registered. ";
  175.       $emess .= "Your new user name and password are: ";
  176.       $emess .= "\n\n\t$username\n\t";
  177.       $emess .= "$password\n\n";
  178.       $emess .= "We appreciate your interest. \n\n";
  179.       $emess .= "If you have any questions or problems,";
  180.       $emess .= " email service@ourstore.com";        
  181.       $subj = "Your new customer registration";    
  182.      # $mailsend=mail("$email","$subj","$emess");      
  183.      header("Location: newUser.php");            
  184.     }
  185.   break;                                            
  186.  
  187.   default:                                            
  188.     include("form.php");
  189. }  
  190. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement