Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.72 KB | None | 0 0
  1. <?php
  2.  
  3. $con = mysql_connect("localhost","hairadmin","hairtest");
  4. function login(){
  5. global $con;
  6. $con = mysql_connect("localhost","hairadmin","hairtest");
  7. if (!$con)
  8.   {
  9.   die('Could not connect: ' . mysql_error());
  10.   }
  11.  
  12. mysql_select_db("hairs", $con);
  13. }
  14.  
  15. function closeCon(){
  16. mysql_close($con);
  17. }
  18.  
  19. function add_trad(){
  20.   global $con;
  21.   $sql="INSERT INTO Translators (FirstName, LastName, Tel, Email, Notes)
  22.  VALUES
  23.  ('$_POST[firstname]','$_POST[lastname]','$_POST[tel]','$_POST[email]','$_POST[notes]')";
  24.  
  25.   if (!mysql_query($sql,$con))
  26.    {
  27.    die('Error: ' . mysql_error());
  28.    }
  29.   header("HTTP/1.0 303 See other");
  30.   header("Location: #");
  31. //echo "1 record added";
  32. }
  33. function edit_trad($trad){
  34.   global $con;
  35.   $sql_edit = mysql_query("SELECT * FROM Translators WHERE ID='$trad'");
  36.   $myTrad = mysql_fetch_array($sql_edit);
  37.   $t = $myTrad['ID'];
  38.   if (isset($_POST['update_t'])) {
  39.       save_trad($trad);
  40.       //show_trad();
  41.       closeCon();
  42.       return;
  43.   }
  44.  
  45.   echo "<div>";
  46.   echo "<h1>Edit " . $myTrad['FirstName'] . $myTrad['LastName'] . "</h1>";
  47.   echo "<br />";
  48.   echo "<form action='' method='post'>";
  49.   echo "Firstname: <input type='text' name='n_firstname' value='" . $myTrad['FirstName']  . "'/>";
  50.   echo "Lastname: <input type='text' name='n_lLastname' value='" . $myTrad['LastName']  . "' />";
  51.   echo "Tel: <input type='text' name='n_tel' value='" . $myTrad['Tel']  . "' />";
  52.   echo "Email: <input type='text' name='n_email' value='" . $myTrad['Email']  . "' />";
  53.   echo "Notes: <input type='text' name='n_notes' value='" . $myTrad['Notes']  . "' />";
  54.   echo "<br /><br /><input type='checkbox' name='update_t'  />";
  55.   echo "<input type='submit' value='SAVE' />";
  56.   echo "</form>";
  57.   echo "</div>";
  58.   echo $trad;
  59. }
  60. function save_trad($trad){
  61.   global $con;
  62.   $sql_save="UPDATE Translators SET FirstName='$_POST[n_firstname]', LastName='$_POST[n_lastname]', Tel='$_POST[n_tel]', Email='$_POST[n_email]', Notes='$_POST[n_notes]') WHERE ID=$trad";
  63.   if (!mysql_query($sql_save,$con))
  64.     {
  65.     die('Error: ' . mysql_error());
  66.     }
  67. //  header("HTTP/1.0 303 See other");
  68. //  header("Location: #");
  69. echo "1 record update:". $trad ;
  70. }
  71.  
  72. function del_trad($trad){
  73.   global $con;
  74.   $sql="DELETE FROM Translators WHERE ID='$trad'";
  75.   if (!mysql_query($sql,$con))
  76.     {
  77.     die('Error: ' . mysql_error());
  78.     }
  79.   header("HTTP/1.0 303 See other");
  80.   header("Location: #");
  81. //echo "ID:". $trad  . "deleted";
  82. }
  83. function show_trad(){
  84.         $result = mysql_query("SELECT * FROM Translators");
  85.         echo "<table border='1'>
  86.        <tr>
  87.        <th>ID</th>
  88.        <th>Firstname</th>
  89.        <th>Lastname</th>
  90.        <th>Tel</th>
  91.        <th>Email</th>
  92.        <th>Notes</th>
  93.        <th>Status</th>
  94.        <th>Edit</th>
  95.        <th>Delete</th>
  96.        </tr>";
  97.         while($row = mysql_fetch_array($result)){
  98.           $ck_del ="del_" . $row['ID'];
  99.           $ck_edit ="edit_" . $row['ID'];
  100.           $a = $row['ID'];
  101.           if (isset($_POST[$ck_del])) {
  102.                 login();
  103.                 del_trad($a);
  104.                 closeCon();
  105.                 return;
  106.           }
  107.           if (isset($_POST[$ck_edit])) {
  108.                 login();
  109.                 edit_trad($a);
  110.                 closeCon();
  111.                 return;
  112.          }
  113.          echo "<tr>";
  114.          echo "<td>" . $row['ID'] . "</td>";
  115.          echo "<td>" . $row['FirstName'] . "</td>";
  116.          echo "<td>" . $row['LastName'] . "</td>";
  117.          echo "<td>" . $row['Tel'] . " <input value='SMS' name='SMS' type='submit' /></td>";
  118.          echo "<td>" . $row['Email'] . " <input value='Send' name='Send' type='submit' /></td>";
  119.          echo "<td>" . $row['Notes'] . "</td>";
  120.          echo "<td>" . $row['Status'] . "</td>";
  121.          echo "<td><form method='post'><input type='checkbox' name='" . $ck_edit . "' /><input value='Edit' name='edit' type='submit' /></form></td>";
  122.          echo "<td><form method='post'><input type='checkbox' name='" . $ck_del . "' /><input value='Delete' name='del' type='submit' /></form></td>";
  123.          echo "</tr>";
  124.          }
  125.         echo "</table>";
  126. }
  127.         login();
  128.         show_trad();
  129.         closeCon();
  130. ?>
  131. <html>
  132. <body>
  133. <div>
  134.  
  135. <h1>New User</h1>
  136. <br />
  137.  
  138. <form action="" method="post">
  139. Firstname: <input type="text" name="firstname" />
  140. Lastname: <input type="text" name="lastname" />
  141. Tel: <input type="text" name="tel" />
  142. Email: <input type="text" name="email" />
  143. Notes: <input type="text" name="notes" />
  144. Active: <input type="checkbox" name="status" value"active" />
  145. <br /><br />
  146. <input type="submit" />
  147. </form>
  148.  
  149. </div>
  150. </body>
  151. </html>
  152.  
  153. <?php
  154. if (isset($_POST['status'])) {
  155.     login();
  156.     add_trad();
  157.    // show_trad();
  158.     closeCon();
  159.     return;
  160. }
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement