Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.80 KB | None | 0 0
  1. <?php
  2. $servername = "mysql.hostinger.co.uk";
  3. $username = "u435963896_root";
  4. $password = "123456";
  5. $dbname = "u435963896_test";
  6. // Create connection
  7. $conn = new mysqli($servername, $username, $password, $dbname);
  8. // Check connection
  9. if ($conn->connect_error)
  10. {
  11. die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14.  
  15.  
  16. ?>
  17.  
  18.  
  19. <!DOCTYPE html>
  20. <html>
  21. <head>
  22. <style>
  23. table, th, td {
  24. border: 1px solid black;
  25. }
  26. </style>
  27. <script>
  28. function validateForm() {
  29. var x = document.forms["myForm"]["email"].value;
  30. if (x == null || x == "") {
  31. alert("Email must be filled out");
  32. return false;
  33. }
  34. }
  35.  
  36.  
  37. function validateForm2() {
  38. var a = document.forms["myForm2"]["company"].value;
  39. var b = document.forms["myForm2"]["product"].value;
  40. var c = document.forms["myForm2"]["founder"].value;
  41. var d = document.forms["myForm2"]["website"].value;
  42. var e = document.forms["myForm2"]["tel"].value;
  43. var f = document.forms["myForm2"]["email"].value;
  44. if (a == null || a == "") {
  45. alert("Company Name must be filled out");
  46. return false; }
  47. else if (b == null || b == "") {
  48. alert("Product/Service must be filled out");
  49. return false; }
  50. else if (c == null || c == "") {
  51. alert("Founder must be filled out");
  52. return false; }
  53. else if (d == null || d == "") {
  54. alert("Website must be filled out");
  55. return false; }
  56. else if (e == null || e == "") {
  57. alert("Tel must be filled out");
  58. return false; }
  59. else if (f == null || f == "") {
  60. alert("Email must be filled out");
  61. return false; }
  62. }
  63.  
  64. function validateForm3() {
  65. var x = document.forms["myForm3"]["selectedno"].value;
  66. if (x == null || x == "") {
  67. ("No must be filled out");
  68. return false;
  69. }
  70. }
  71.  
  72. function areusure()
  73. {
  74. var x=confirm("Are you sure?");
  75. if (x==true)
  76. {
  77. var y=1;
  78. }
  79. else
  80. {
  81. var y=2;
  82. }
  83. }
  84. </script>
  85. </head>
  86. <body>
  87.  
  88.  
  89. <?php
  90.  
  91. if (isset($_POST['chooserow']))
  92. {
  93. $selectedno = $_POST['selectedno'];
  94.  
  95. session_start();
  96. $_SESSION['no'] = $_POST['selectedno'];
  97.  
  98. $sql = "SELECT * FROM nef WHERE No=$selectedno";
  99. $result = $conn->query($sql);
  100.  
  101. if ($result->num_rows > 0)
  102. {
  103. while($row = $result->fetch_assoc())
  104. {
  105. $selectedID = $row["ID"];
  106. $selectedno = $row["No"];
  107. $selectedcompany = $row["Company"];
  108. $selectedproduct = $row["Product"];
  109. $selectedfounder = $row["Founder"];
  110. $selectedwebsite = $row["Website"];
  111. $selectedtel = $row["Tel"];
  112. $selectedemail = $row["Email"];
  113. }
  114. //print '<script type="text/javascript">';
  115. //print 'alert("';
  116. //print $selectedcompany;
  117. //print $selectedproduct;
  118. //print $selectedfounder;
  119. //print $selectedwebsite;
  120. //print $selectedtel;
  121. //print $selectedemail;
  122. //print '")';
  123. //print '</script>';
  124. }
  125. else
  126. {
  127. print '<script type="text/javascript">';
  128. print 'alert("';
  129. print 'Error: No data with No '. $selectedno . ' exist.';
  130. print '")';
  131. print '</script>';
  132. }
  133.  
  134. $editID = $selectedID;
  135. $editno = $selectedno;
  136. $editcompany = $selectedcompany;
  137. $editproduct = $selectedproduct;
  138. $editfounder = $selectedfounder;
  139. $editwebsite = $selectedwebsite;
  140. $edittel = $selectedtel;
  141. $editemail = $selectedemail;
  142.  
  143. }
  144.  
  145.  
  146.  
  147. ?>
  148.  
  149.  
  150.  
  151. <form method="post" action="index.php">
  152. <br>
  153. <input type="submit" name="selectallmail" value="Select all email">
  154. <br>
  155. </form>
  156.  
  157. <form name="myForm" onsubmit="return validateForm()" method="post" action="index.php">
  158. <br>
  159. Send table to this email : <input type="text" name="email" value="" required>
  160. <input type="submit" name="sendtable" value="Send Table">
  161. <br>
  162. </form>
  163. <br>
  164. <br>
  165. <br>
  166. <br>
  167. <br>
  168. <table>
  169. <tr><td>
  170. <form name="myForm2" onsubmit="return validateForm2()" method="post" action="index.php">
  171. <br>
  172. <input type="submit" name="adddata" value="Add data">
  173. <br>
  174. <br>
  175. <table>
  176. <th>Column</th><th>Data</th>
  177. <tr><td>Company Name :</td><td><input type="text" name="company" value="" required></td>
  178. <tr><td>Product/Service :</td><td><input type="text" name="product" value="" required></td>
  179. <tr><td>Founder :</td><td><input type="text" name="founder" value="" required></td>
  180. <tr><td>Website :</td><td><input type="text" name="website" value="" required></td>
  181. <tr><td>Tel :</td><td><input type="text" name="tel" value="" required></td>
  182. <tr><td>Email :</td><td><input type="text" name="email" value="" required></td>
  183. </table>
  184. <br>
  185.  
  186. </form>
  187. </td><td>
  188. <form name="myForm3" onsubmit="return validateForm3()" method="post" action="index.php">
  189. <br>
  190. To edit / delete, choose a row no :
  191. <input size="10" type="text" name="selectedno" value="" required>
  192. <input type="submit" name="chooserow" value="Choose row">
  193. </form>
  194. <form name="myForm4" method="post" action="index.php">
  195. <br>
  196. <br>
  197. <table align=center><col width="150"><col width="280">
  198. <th>Column</th><th>Data</th>
  199. <tr><td>ID :</td><td><input size="50" type="int" name="ID" value="<?php print $selectedID; ?>" readonly required></td>
  200. <tr><td>No :</td><td><input size="50" type="int" name="no" value="<?php print $selectedno; ?>" readonly required></td>
  201. <tr><td>Company Name :</td><td><input size="50" type="text" name="company" value="<?php print $selectedcompany; ?>" ></td>
  202. <tr><td>Product/Service :</td><td><input size="50" type="text" name="product" value="<?php print $selectedproduct; ?>" ></td>
  203. <tr><td>Founder :</td><td><input size="50" type="text" name="founder" value="<?php print $selectedfounder; ?>" ></td>
  204. <tr><td>Website :</td><td><input size="50" type="text" name="website" value="<?php print $selectedwebsite; ?>" ></td>
  205. <tr><td>Tel :</td><td><input size="50" type="text" name="tel" value="<?php print $selectedtel; ?>" ></td>
  206. <tr><td>Email :</td><td><input size="50" type="text" name="email" value="<?php print $selectedemail; ?>" ></td>
  207. </table>
  208. <br>
  209. Click here to submit edited data :<input type="submit" name="editdata" value="Edit data">
  210. <br>
  211. <br>
  212. <input type="submit" name="deletedata" value="DELETE"> << Click here to delete the data
  213.  
  214. </form>
  215. </td>
  216. </table>
  217.  
  218.  
  219. <br>
  220. <br>
  221. <br>
  222.  
  223. <?php
  224.  
  225. unset($array);
  226. unset($mailray);
  227. $mailray = array();
  228. $email;
  229. $array = array();
  230. $mrow = "Maxrow:";
  231.  
  232.  
  233. $sql = "SELECT No, Company, Product, Founder, Website, Tel, Email FROM nef ORDER BY No ASC";
  234. $result = $conn->query($sql);
  235.  
  236. if ($result->num_rows > 0)
  237. {
  238. echo "<table> <tr>
  239. <th>No</th>
  240. <th>Company</th>
  241. <th>Product/Service</th>
  242. <th>Founder</th>
  243. <th>Website</th>
  244. <th>Tel</th>
  245. <th>Email</th>
  246. </tr>";
  247. // output data of each row
  248. while($row = $result->fetch_assoc())
  249. {
  250. $array[] = $row;
  251. echo " <tr> <td>" . $row["No"]. "</td>
  252. <td>" . $row["Company"]. "</td>
  253. <td>" . $row["Product"]. "</td>
  254. <td>" . $row["Founder"]. "</td>
  255. <td align=center>" . $row["Website"]. "</td>
  256. <td align=center>" . $row["Tel"]. "</td>
  257. <td align=center>" . $row["Email"]. "</td>
  258. </tr>";
  259. }
  260. echo "</table>";
  261. }
  262. else
  263. {
  264. echo "0 results";
  265. }
  266. $maxrow = count($array);
  267. //echo $email;
  268.  
  269. ?>
  270.  
  271. <?php
  272.  
  273. if (isset($_POST['sendtable']))
  274. {
  275. $email = $_POST['email'];
  276. $to = $email;
  277. $send = $send++;
  278. $subject = "NEF (Malaysian Association of Bumiputera ICT Industry and Entrepreneurs)";
  279.  
  280. $message = '<html><body>';
  281. $message .= '<table border cellpadding="10"><tr><th>No</th><th>Company</th><th>Product/Service</th><th>Founder</th><th>Website</th><th>Tel</th><th>Email</th></tr>';
  282.  
  283. $maxrow = count($array);
  284.  
  285.  
  286. $i = 0;
  287. //$u = 1;
  288. while($i < $maxrow)
  289. {
  290. $message .= '<tr><td align="center"><font size="6">' . print_r ($array[$i]['No'], true) . '</font></td>';
  291. $message .= '<td><font size="4">' . print_r ($array[$i]['Company'], true) . '</font></td>';
  292. $message .= '<td><font size="4">' . print_r ($array[$i]['Product'], true) . '</font></td>';
  293. $message .= '<td><font size="4">' . print_r ($array[$i]['Founder'], true) . '</font></td>';
  294. $message .= '<td align="center"><font size="4">' . print_r ($array[$i]['Website'], true) . '</font></td>';
  295. $message .= '<td align="center"><font size="4">' . print_r ($array[$i]['Tel'], true) . '</font></td>';
  296. $message .= '<td align="center"><font size="4">' . print_r ($array[$i]['Email'], true) . '</font></td></tr>';
  297. $i++;
  298. //$u++;
  299. }
  300.  
  301. $message .= "</table>";
  302. $message .= "</body></html>";
  303.  
  304. $headers = "From: qweee@mail.com" . "\r\n";
  305. $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
  306. $headers .= "BCC: loadingjunks@gmail.com\r\n";
  307. $headers .= "MIME-Version: 1.0\r\n";
  308. $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  309.  
  310. print '<script type="text/javascript">';
  311. print 'alert("The table has been sent to '. $_POST['email'].' :)")';
  312. print '</script>';
  313.  
  314. mail($to,$subject,$message,$headers);
  315. }
  316.  
  317. if (isset($_POST['selectallmail']))
  318. {
  319. $email;
  320.  
  321.  
  322.  
  323. $sql = "SELECT Email FROM nef ORDER BY No ASC";
  324. $result = $conn->query($sql);
  325.  
  326. if ($result->num_rows > 0)
  327. {
  328. while($row = $result->fetch_assoc())
  329. {
  330. $mailray[] = $row;
  331. }
  332.  
  333. $t = 0;
  334. print '<script type="text/javascript">';
  335. print 'alert("';
  336. while($t < $maxrow)
  337. {
  338. print ($mailray[$t]['Email']) . '\n';
  339. $t++;
  340. };
  341. print '")';
  342. print '</script>';
  343. }
  344. else
  345. {
  346. print '<script type="text/javascript">';
  347. print 'alert("';
  348. print '0 results';
  349. print '")';
  350. print '</script>';
  351. }
  352.  
  353. }
  354.  
  355. if (isset($_POST['adddata']))
  356. {
  357. $maxrow = $maxrow+1;
  358. $No = $maxrow++;
  359. $company = $_POST['company'];
  360. $product = $_POST['product'];
  361. $founder = $_POST['founder'];
  362. $website = $_POST['website'];
  363. $tel = $_POST['tel'];
  364. $email = $_POST['email'];
  365.  
  366.  
  367. $sql = "INSERT INTO nef (ID, No, Company, Product, Founder, Website, Tel, Email) VALUES ('', '$No', '$company', '$product', '$founder', '$website', '$tel', '$email')";
  368. //$result = $conn->query($sql);
  369.  
  370. if ($conn->query($sql) === TRUE)
  371. {
  372. print '<script type="text/javascript">';
  373. print 'alert("';
  374. print 'Row added';
  375. print '")';
  376. print '</script>';
  377. header("Location: http://yvibojnl.esy.es");
  378. }
  379. else
  380. {
  381. print '<script type="text/javascript">';
  382. print 'alert("';
  383. print 'Error updating record';
  384. print '")';
  385. print '</script>';
  386. }
  387.  
  388.  
  389. }
  390.  
  391. if (isset($_POST['editdata']))
  392. {
  393. $editID = $_POST['ID'];
  394. $editno = $_POST['no'];
  395. $company = $_POST['company'];
  396. $product = $_POST['product'];
  397. $founder = $_POST['founder'];
  398. $website = $_POST['website'];
  399. $tel = $_POST['tel'];
  400. $email = $_POST['email'];
  401.  
  402. $sql = "SELECT * FROM nef WHERE ID='$editID'";
  403. //$sql = $conn->query("UPDATE nef SET Product='$product' WHERE ID='$editID'");
  404. //$sql2 = "UPDATE nef SET No='$editno', Company='$company', Product='$product', Founder='$founder', Website='$website', Tel='$tel', Email='$email' WHERE ID='$editID'";
  405. $result = $conn->query($sql);
  406. $row = $result->num_rows;
  407. if ($row)
  408. {
  409. $sql2 = "UPDATE nef SET Company='$company', Product='$product', Founder='$founder', Website='$website', Tel='$tel', Email='$email' WHERE ID='$editID'";
  410. $result = $conn->query($sql2);
  411. $sql = "SELECT * FROM nef WHERE ID='$editID'";
  412. $result = $conn->query($sql);
  413. if ($row)
  414. {
  415. $abc = $result->fetch_assoc();
  416. }
  417.  
  418. header("Location: http://yvibojnl.esy.es");
  419.  
  420. //print '<script type="text/javascript">';
  421. //print 'alert("';
  422. //print 'shit';
  423. //print '")';
  424. //print '</script>';
  425. }
  426. else
  427. {
  428. //print '<script type="text/javascript">';
  429. //print 'alert("';
  430. //print $editID;
  431. //print $editno;
  432. //print $editcompany;
  433. //print $editproduct;
  434. //print $editfounder;
  435. //print $editwebsite;
  436. //print $edittel;
  437. //print $editemail;
  438. //print 'Error: Please choose row first. (Connection Error)';
  439. //print '")';
  440. //print '</script>';
  441. }
  442.  
  443.  
  444.  
  445. }
  446.  
  447. if (isset($_POST['deletedata']))
  448. {
  449. $deleteID = $_POST['ID'];
  450. $sql = "DELETE FROM nef WHERE ID='$deleteID'";
  451. $conn->query($sql);
  452. header("Location: http://yvibojnl.esy.es");
  453.  
  454. }
  455.  
  456. //print_r ($array);
  457. //echo $company;
  458.  
  459. ?>
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. </body>
  467. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement