Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.49 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include_once('connect_db.php');
  4. if(isset($_SESSION['username'])){
  5. $id=$_SESSION['admin_id'];
  6. $username=$_SESSION['username'];
  7. }else{
  8. header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php");
  9. exit();
  10. }
  11. if(isset($_POST['submit'])){
  12. $fname=$_POST['first_name'];
  13. if (!preg_match("/^[a-zA-Z ]*$/",$fname))
  14.   {
  15.   $nameErr = "Only letters and white space allowed";
  16.   }
  17. $lname=$_POST['last_name'];
  18. $sid=$_POST['staff_id'];
  19. $postal=$_POST['postal_address'];
  20. $phone=$_POST['phone'];
  21. $email=$_POST['email'];
  22. $user=$_POST['username'];
  23. $pas=$_POST['password'];
  24. $sql1=mysql_query("SELECT * FROM cashier WHERE username='$user'")or die(mysql_error());
  25.  $result=mysql_fetch_array($sql1);
  26.  if($result>0){
  27. $message="<font color=blue>sorry the username entered already exists</font>";
  28.  }else{
  29. $sql=mysql_query("INSERT INTO cashier(first_name,last_name,staff_id,postal_address,phone,email,username,password,date)
  30. VALUES('$fname','$lname','$sid','$postal','$phone','$email','$user','$pas',NOW())");
  31. if($sql>0) {header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/admin_cashier.php");
  32. }else{
  33. $message1="<font color=red>Registration Failed, Try again</font>";
  34. }
  35.     }}
  36. ?>
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40. <title><?php echo $username;?> - Pharmacy Sys</title>
  41. <link rel="stylesheet" type="text/css" href="style/mystyle.css">
  42. <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
  43. <link rel="stylesheet" href="style/table.css" type="text/css" media="screen" />
  44. <script src="js/function.js" type="text/javascript"></script>
  45. <script src="js/validation_script.js" type="text/javascript"></script>
  46. <!--<script>
  47. function validateForm()
  48. {
  49.  
  50. //for alphabet characters only
  51. var str=document.form1.first_name.value;
  52.     var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  53.     //comparing user input with the characters one by one
  54.     for(i=0;i<str.length;i++)
  55.     {
  56.     //charAt(i) returns the position of character at specific index(i)
  57.     //indexOf returns the position of the first occurence of a specified value in a string. this method returns -1 if the value to search for never ocurs
  58.     if(valid.indexOf(str.charAt(i))==-1)
  59.     {
  60.     alert("First Name Cannot Contain Numerical Values");
  61.     document.form1.first_name.value="";
  62.     document.form1.first_name.focus();
  63.     return false;
  64.     }}
  65.    
  66. if(document.form1.first_name.value=="")
  67. {
  68. alert("Name Field is Empty");
  69. return false;
  70. }
  71.  
  72. //for alphabet characters only
  73. var str=document.form1.last_name.value;
  74.     var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  75.     //comparing user input with the characters one by one
  76.     for(i=0;i<str.length;i++)
  77.     {
  78.     //charAt(i) returns the position of character at specific index(i)
  79.     //indexOf returns the position of the first occurence of a specified value in a string. this method returns -1 if the value to search for never ocurs
  80.     if(valid.indexOf(str.charAt(i))==-1)
  81.     {
  82.     alert("Last Name Cannot Contain Numerical Values");
  83.     document.form1.last_name.value="";
  84.     document.form1.last_name.focus();
  85.     return false;
  86.     }}
  87.    
  88.  
  89. if(document.form1.last_name.value=="")
  90. {
  91. alert("Name Field is Empty");
  92. return false;
  93. }
  94.  
  95. }
  96.  
  97. </script>-->
  98.  <style>
  99. <style>#left-column {height: 477px;}
  100.  #main {height: 477px;}</style>
  101.  </style>
  102. </head>
  103. <body>
  104. <div id="content">
  105. <div id="header">
  106. <h1><a href="#"><img src="images/hd_logo.jpg"></a> Pharmacy Sys</h1></div>
  107. <div id="left_column">
  108. <div id="button">
  109. <ul>
  110.             <li><a href="admin.php">Dashboard</a></li>
  111.             <li><a href="admin_pharmacist.php">Pharmacist</a></li>
  112.             <li><a href="admin_manager.php">Manager</a></li>
  113.             <li><a href="admin_cashier.php">Cashier</a></li>
  114.             <li><a href="logout.php">Logout</a></li>
  115.         </ul>  
  116. </div>
  117.         </div>
  118. <div id="main">
  119. <div id="tabbed_box" class="tabbed_box">  
  120.     <h4>Manage Cashier</h4>
  121. <hr/>  
  122.     <div class="tabbed_area">  
  123.    
  124.      
  125.         <ul class="tabs">  
  126.             <li><a href="javascript:tabSwitch('tab_1', 'content_1');" id="tab_1" class="active">View User</a></li>  
  127.             <li><a href="javascript:tabSwitch('tab_2', 'content_2');" id="tab_2">Add User</a></li>  
  128.              
  129.         </ul>  
  130.          
  131.         <div id="content_1" class="content">  
  132.         <?php echo $message;
  133.               echo $message1;
  134.              
  135.         /*
  136.         View
  137.         Displays all data from 'Cashier' table
  138.         */
  139.  
  140.         // connect to the database
  141.         include_once('connect_db.php');
  142.  
  143.         // get results from database
  144.        
  145.         $result = mysql_query("SELECT * FROM cashier")
  146.                 or die(mysql_error());
  147.                
  148.                        
  149.         // display data in table
  150.        
  151.         echo "<table border='1' cellpadding='5' align='center'>";
  152.         echo "<tr> <th>ID</th><th>Firstname </th> <th>Lastname </th> <th>Username </th><th>Update </th><th>Delete</th></tr>";
  153.  
  154.         // loop through results of database query, displaying them in the table
  155.         while($row = mysql_fetch_array( $result )) {
  156.                
  157.                 // echo out the contents of each row into a table
  158.                 echo "<tr>";
  159.                
  160.                 echo '<td>' . $row['cashier_id'] . '</td>';
  161.                 echo '<td>' . $row['first_name'] . '</td>';
  162.                 echo '<td>' . $row['last_name'] . '</td>';
  163.                 echo '<td>' . $row['username'] . '</td>';
  164.                 ?>
  165.                 <td><a href="update_cashier.php?username=<?php echo $row['username']?>"><img src="images/update-icon.png" width="35" height="35" border="0" /></a></td>
  166.                 <td><a href="delete_cashier.php?cashier_id=<?php echo $row['cashier_id']?>"><img src="images/delete-icon.jpg" width="35" height="35" border="0" /></a></td>
  167.                 <?php
  168.          }
  169.         // close table>
  170.         echo "</table>";
  171. ?>
  172.         </div>  
  173.         <div id="content_2" class="content">  
  174.                    <!--Cashier-->
  175.         <?php echo $message;
  176.               echo $message1;
  177.               ?>
  178.         <form name="form1"  onsubmit="return validateForm(validation_script.js);" action="admin_cashier.php" method="post" >
  179.             <table width="220" height="106" border="0" >   
  180.                 <tr><td align="center"><input name="first_name" type="text" style="width:170px" placeholder="First Name" required="required"  id="first_name" /></td></tr>
  181.                 <tr><td align="center"><input name="last_name" type="text" style="width:170px" placeholder="Last Name" required="required" id="last_name" /></td></tr>
  182.                 <tr><td align="center"><input name="staff_id" type="text" style="width:170px" placeholder="Staff ID" required="required" id="staff_id"/></td></tr>  
  183.                 <tr><td align="center"><input name="postal_address" type="text" style="width:170px" placeholder="Address" required="required" id="postal_address" /></td></tr>  
  184.                 <tr><td align="center"><input name="phone" type="text" style="width:170px"placeholder="Phone"  required="required" id="phone" /></td></tr>  
  185.                 <tr><td align="center"><input name="email" type="email" style="width:170px" placeholder="Email" required="required" id="email" /></td></tr>  
  186.                 <tr><td align="center"><input name="username" type="text" style="width:170px" placeholder="Username" required="required" id="username" /></td></tr>
  187.                 <tr><td align="center"><input name="password" type="password" style="width:170px" placeholder="Password" required="required" id="password"/></td></tr>
  188.                 <tr><td align="right"><input name="submit" type="submit" value="Submit"></td></tr>
  189.                
  190.             </table>
  191.         </form>
  192.         </div>  
  193.        
  194.      
  195.     </div>  
  196.  
  197. </div>
  198.  
  199. </div>
  200. <div id="footer" align="Center"> Pharmacy Sys 2013. Copyright All Rights Reserved</div>
  201. </div>
  202. </body>
  203. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement