Advertisement
Guest User

Untitled

a guest
Apr 14th, 2017
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. <?php
  2. $host= "localhost";
  3. $user= getenv('C9_USER');
  4. $pass= "";
  5. $db= "c9";
  6. $port= "3306";
  7.  
  8. //create a connection
  9. $db=mysqli_connect($host, $user, $pass, $db,$port);
  10. if($db->connect_error){
  11. die("Connection failed: " . $db->connect_error);
  12. }
  13. echo "Connected successfully (".$db->host_info.")";
  14.  
  15.  
  16. $thisPHP = $_SERVER['PHP_SELF'];
  17.  
  18. echo<<<EOE
  19. <form action="$thisPHP" method="post">
  20. Name:<input type="text" name="Name" size="40" title="only underline allowed,the size must be 3 to 16 long numbers or characters " pattern="^[a-zA-Z0-9_-]{3,16}$" required ><br>
  21. Address:<input type="text" name="Address" title="validate address" required><br>
  22. Phone:<input type="number" name="Phone_number" size="10" title="xxx-yyy-zzzz, area code optional" pattern="^(\d{3}-)?\d{3}-\d{4}$" required ><br>
  23. Email:<input type="text" name="Email" size="40" title="x@y.z, x and y can have . or -, z only 2 or 3 letters" pattern="^\w+([.-]?\w+)*(\.\w{2,3}})$" required>
  24. Avaliability: <input type="radio" name="Avaliable" value="Now" checked required="required">Now: (&lt; 1 Month) <br>
  25. <input type="radio" name="Avaliable" value="Soon" >Soon: (1-3 months)<br>
  26. <input type="radio" name="Avaliable" value="Exploring">Upcoming: (3+ months)<br>
  27. Company:
  28. <input type="text" name="Company"><br>
  29. Job:
  30. <input type="text" name="Job"><br>
  31. Description:
  32. <input type="text" name="Description"><br>
  33. Skills:
  34. <select name="Skill" required>
  35. <option value="SQL">SQL</option>
  36. <option value="Java">Java</option>
  37. <option value="HTML">HTML</option>
  38. <option value="Javascript">Javascript</option>
  39. <option value="C++">C++</option>
  40. <option value="C#">C#</option>
  41. <option value="XML">XML</option>
  42. <option value="C">C</option>
  43. <option value="Perl">Perl</option>
  44. <option value="Python">Python</option>
  45. <option value="PHP">PHP</option>
  46. </select>
  47.  
  48. Experience:
  49. <select name="period">
  50. <option value="0" checked required="required" >0</option>
  51. <option value="1-3">1-3</option>
  52. <option value="3-5">3-5</option>
  53. <option value="5-10">5-10</option>
  54. <option value="10+">10+</option>
  55. </select>
  56. <br>
  57. Position:
  58. <input type="radio" name="Position" value="Team-Member" checked required="required" >Team-Member<br>
  59. <input type="radio" name="Position" value="Team Leader">Team Leader<br>
  60. <input type="radio" name="Position" value="Executive">Executive<br>
  61. <input type="submit" name="Add" value="Add"><br>
  62. <input type="reset" name="reset" value="reset"><br>
  63. </form>
  64.  
  65. EOE;
  66.  
  67.  
  68.  
  69. //start executing the script
  70. $name=$_POST['Name'];
  71. $address=$_POST['Address'];
  72. $phone_Number=$_POST['Phone_number'];
  73. $email=$_POST['Email'];
  74. $avaliable=$_POST['Avaliable'];
  75. $company=$_POST['Company'];
  76. $job=$_POST['Job'];
  77. $description=$_POST['Description'];
  78. $skill=$_POST['Skill'];
  79. $period=$_POST['period'];
  80. $pos=$_POST['Position'];
  81.  
  82. if(isset($_POST['Add'])){
  83. $sql="INSERT INTO employee(name, address, phone, email, availability, company_name, job_title, description, skill, period, position) VALUES ('$name','$address','$phone_Number','$email','$avaliable','$company','$job','$description','$skill','$period','$pos')";
  84. $db->query($sql);}
  85.  
  86. if(isset($_POST["Update"])){
  87. $sql="UPDATE employee SET address='$address',phone='$phone_Number',email='$email',availability='$avaliable',company_name='$company',job_title='$job',description='$description',skill='$skill',period='$period',position='$pos' WHERE name='$name' ";
  88. $db->query($sql);}
  89.  
  90. //check if delete is selected
  91.  
  92. if(isset($_POST['btnDelete'])){
  93. $name=$_POST['Name'];
  94. $sql="DELETE FROM employee WHERE name='$name'";
  95. $db->query($sql);}
  96.  
  97. $sql="SELECT * FROM employee";
  98. $result=$db->query($sql);
  99.  
  100. if($result->num_rows >0){
  101. //output data of each row
  102. while($row =$result->fetch_assoc()){
  103.  
  104. $name=$row["name"];
  105. $address=$row["address"];
  106. $phone_Number=$row["phone"];
  107. $email=$row["email"];
  108. $avaliable=$row["availability"];
  109. $company=$row["company_name"];
  110. $job=$row["job_title"];
  111. $description=$row["description"];
  112. $skill=$row["skill"];
  113. $period=$row["period"];
  114. $pos=$row["position"];
  115.  
  116. echo <<<EOE
  117. <form action="$thisPHP" method="post">
  118. Name:<input type="text" name="Name" value='$name' readonly><br>
  119. Address:<input type="text" name="Address" value='$address'><br>
  120. Phone:<input type="number" name="Phone_number" value='$phone_Number'><br>
  121. Email:<input type="text" name="Email" value='$email'>
  122. Avaliability:<input type="radio" name="Avaliable" value='$avaliable' checked>$avaliable<br>
  123. Company:<input type="text" name="Company" value='$company'><br>
  124. Job:<input type="text" name="Job" value='$job'><br>
  125. Description:<input type="text" name="Description" value='$description'><br>
  126.  
  127. <span>Skills</span>
  128. <select name="Skill">
  129. <option value='$skill'>$skill</option>
  130. </select>
  131.  
  132. <span>Experience:</span>
  133. <select name="period">
  134. <option value='$period'>$period</option>
  135. </select>
  136. <br>
  137.  
  138. <span>Position:</span>
  139. <input type="radio" name="Position" value='$pos' checked >$pos<br>
  140. <input type="submit" value="update" name='Update'><br>
  141. <input type="submit" value="Delete" name="btnDelete"><br>
  142. </form>
  143. EOE;
  144. }
  145. }
  146. ?>
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement