Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "mysql.hostinger.co.uk";
- $username = "u435963896_root";
- $password = "123456";
- $dbname = "u435963896_test";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- table, th, td {
- border: 1px solid black;
- }
- </style>
- <script>
- function validateForm() {
- var x = document.forms["myForm"]["email"].value;
- if (x == null || x == "") {
- alert("Email must be filled out");
- return false;
- }
- }
- function validateForm2() {
- var a = document.forms["myForm2"]["company"].value;
- var b = document.forms["myForm2"]["product"].value;
- var c = document.forms["myForm2"]["founder"].value;
- var d = document.forms["myForm2"]["website"].value;
- var e = document.forms["myForm2"]["tel"].value;
- var f = document.forms["myForm2"]["email"].value;
- if (a == null || a == "") {
- alert("Company Name must be filled out");
- return false; }
- else if (b == null || b == "") {
- alert("Product/Service must be filled out");
- return false; }
- else if (c == null || c == "") {
- alert("Founder must be filled out");
- return false; }
- else if (d == null || d == "") {
- alert("Website must be filled out");
- return false; }
- else if (e == null || e == "") {
- alert("Tel must be filled out");
- return false; }
- else if (f == null || f == "") {
- alert("Email must be filled out");
- return false; }
- }
- function validateForm3() {
- var x = document.forms["myForm3"]["selectedno"].value;
- if (x == null || x == "") {
- ("No must be filled out");
- return false;
- }
- }
- function areusure()
- {
- var x=confirm("Are you sure?");
- if (x==true)
- {
- var y=1;
- }
- else
- {
- var y=2;
- }
- }
- </script>
- </head>
- <body>
- <?php
- if (isset($_POST['chooserow']))
- {
- $selectedno = $_POST['selectedno'];
- session_start();
- $_SESSION['no'] = $_POST['selectedno'];
- $sql = "SELECT * FROM nef WHERE No=$selectedno";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- $selectedID = $row["ID"];
- $selectedno = $row["No"];
- $selectedcompany = $row["Company"];
- $selectedproduct = $row["Product"];
- $selectedfounder = $row["Founder"];
- $selectedwebsite = $row["Website"];
- $selectedtel = $row["Tel"];
- $selectedemail = $row["Email"];
- }
- //print '<script type="text/javascript">';
- //print 'alert("';
- //print $selectedcompany;
- //print $selectedproduct;
- //print $selectedfounder;
- //print $selectedwebsite;
- //print $selectedtel;
- //print $selectedemail;
- //print '")';
- //print '</script>';
- }
- else
- {
- print '<script type="text/javascript">';
- print 'alert("';
- print 'Error: No data with No '. $selectedno . ' exist.';
- print '")';
- print '</script>';
- }
- $editID = $selectedID;
- $editno = $selectedno;
- $editcompany = $selectedcompany;
- $editproduct = $selectedproduct;
- $editfounder = $selectedfounder;
- $editwebsite = $selectedwebsite;
- $edittel = $selectedtel;
- $editemail = $selectedemail;
- }
- ?>
- <form method="post" action="index.php">
- <br>
- <input type="submit" name="selectallmail" value="Select all email">
- <br>
- </form>
- <form name="myForm" onsubmit="return validateForm()" method="post" action="index.php">
- <br>
- Send table to this email : <input type="text" name="email" value="" required>
- <input type="submit" name="sendtable" value="Send Table">
- <br>
- </form>
- <br>
- <br>
- <br>
- <br>
- <br>
- <table>
- <tr><td>
- <form name="myForm2" onsubmit="return validateForm2()" method="post" action="index.php">
- <br>
- <input type="submit" name="adddata" value="Add data">
- <br>
- <br>
- <table>
- <th>Column</th><th>Data</th>
- <tr><td>Company Name :</td><td><input type="text" name="company" value="" required></td>
- <tr><td>Product/Service :</td><td><input type="text" name="product" value="" required></td>
- <tr><td>Founder :</td><td><input type="text" name="founder" value="" required></td>
- <tr><td>Website :</td><td><input type="text" name="website" value="" required></td>
- <tr><td>Tel :</td><td><input type="text" name="tel" value="" required></td>
- <tr><td>Email :</td><td><input type="text" name="email" value="" required></td>
- </table>
- <br>
- </form>
- </td><td>
- <form name="myForm3" onsubmit="return validateForm3()" method="post" action="index.php">
- <br>
- To edit / delete, choose a row no :
- <input size="10" type="text" name="selectedno" value="" required>
- <input type="submit" name="chooserow" value="Choose row">
- </form>
- <form name="myForm4" method="post" action="index.php">
- <br>
- <br>
- <table align=center><col width="150"><col width="280">
- <th>Column</th><th>Data</th>
- <tr><td>ID :</td><td><input size="50" type="int" name="ID" value="<?php print $selectedID; ?>" readonly required></td>
- <tr><td>No :</td><td><input size="50" type="int" name="no" value="<?php print $selectedno; ?>" readonly required></td>
- <tr><td>Company Name :</td><td><input size="50" type="text" name="company" value="<?php print $selectedcompany; ?>" ></td>
- <tr><td>Product/Service :</td><td><input size="50" type="text" name="product" value="<?php print $selectedproduct; ?>" ></td>
- <tr><td>Founder :</td><td><input size="50" type="text" name="founder" value="<?php print $selectedfounder; ?>" ></td>
- <tr><td>Website :</td><td><input size="50" type="text" name="website" value="<?php print $selectedwebsite; ?>" ></td>
- <tr><td>Tel :</td><td><input size="50" type="text" name="tel" value="<?php print $selectedtel; ?>" ></td>
- <tr><td>Email :</td><td><input size="50" type="text" name="email" value="<?php print $selectedemail; ?>" ></td>
- </table>
- <br>
- Click here to submit edited data :<input type="submit" name="editdata" value="Edit data">
- <br>
- <br>
- <input type="submit" name="deletedata" value="DELETE"> << Click here to delete the data
- </form>
- </td>
- </table>
- <br>
- <br>
- <br>
- <?php
- unset($array);
- unset($mailray);
- $mailray = array();
- $email;
- $array = array();
- $mrow = "Maxrow:";
- $sql = "SELECT No, Company, Product, Founder, Website, Tel, Email FROM nef ORDER BY No ASC";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- echo "<table> <tr>
- <th>No</th>
- <th>Company</th>
- <th>Product/Service</th>
- <th>Founder</th>
- <th>Website</th>
- <th>Tel</th>
- <th>Email</th>
- </tr>";
- // output data of each row
- while($row = $result->fetch_assoc())
- {
- $array[] = $row;
- echo " <tr> <td>" . $row["No"]. "</td>
- <td>" . $row["Company"]. "</td>
- <td>" . $row["Product"]. "</td>
- <td>" . $row["Founder"]. "</td>
- <td align=center>" . $row["Website"]. "</td>
- <td align=center>" . $row["Tel"]. "</td>
- <td align=center>" . $row["Email"]. "</td>
- </tr>";
- }
- echo "</table>";
- }
- else
- {
- echo "0 results";
- }
- $maxrow = count($array);
- //echo $email;
- ?>
- <?php
- if (isset($_POST['sendtable']))
- {
- $email = $_POST['email'];
- $to = $email;
- $send = $send++;
- $subject = "NEF (Malaysian Association of Bumiputera ICT Industry and Entrepreneurs)";
- $message = '<html><body>';
- $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>';
- $maxrow = count($array);
- $i = 0;
- //$u = 1;
- while($i < $maxrow)
- {
- $message .= '<tr><td align="center"><font size="6">' . print_r ($array[$i]['No'], true) . '</font></td>';
- $message .= '<td><font size="4">' . print_r ($array[$i]['Company'], true) . '</font></td>';
- $message .= '<td><font size="4">' . print_r ($array[$i]['Product'], true) . '</font></td>';
- $message .= '<td><font size="4">' . print_r ($array[$i]['Founder'], true) . '</font></td>';
- $message .= '<td align="center"><font size="4">' . print_r ($array[$i]['Website'], true) . '</font></td>';
- $message .= '<td align="center"><font size="4">' . print_r ($array[$i]['Tel'], true) . '</font></td>';
- $message .= '<td align="center"><font size="4">' . print_r ($array[$i]['Email'], true) . '</font></td></tr>';
- $i++;
- //$u++;
- }
- $message .= "</table>";
- $message .= "</body></html>";
- $headers = "From: qweee@mail.com" . "\r\n";
- $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
- $headers .= "BCC: loadingjunks@gmail.com\r\n";
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
- print '<script type="text/javascript">';
- print 'alert("The table has been sent to '. $_POST['email'].' :)")';
- print '</script>';
- mail($to,$subject,$message,$headers);
- }
- if (isset($_POST['selectallmail']))
- {
- $email;
- $sql = "SELECT Email FROM nef ORDER BY No ASC";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- $mailray[] = $row;
- }
- $t = 0;
- print '<script type="text/javascript">';
- print 'alert("';
- while($t < $maxrow)
- {
- print ($mailray[$t]['Email']) . '\n';
- $t++;
- };
- print '")';
- print '</script>';
- }
- else
- {
- print '<script type="text/javascript">';
- print 'alert("';
- print '0 results';
- print '")';
- print '</script>';
- }
- }
- if (isset($_POST['adddata']))
- {
- $maxrow = $maxrow+1;
- $No = $maxrow++;
- $company = $_POST['company'];
- $product = $_POST['product'];
- $founder = $_POST['founder'];
- $website = $_POST['website'];
- $tel = $_POST['tel'];
- $email = $_POST['email'];
- $sql = "INSERT INTO nef (ID, No, Company, Product, Founder, Website, Tel, Email) VALUES ('', '$No', '$company', '$product', '$founder', '$website', '$tel', '$email')";
- //$result = $conn->query($sql);
- if ($conn->query($sql) === TRUE)
- {
- print '<script type="text/javascript">';
- print 'alert("';
- print 'Row added';
- print '")';
- print '</script>';
- header("Location: http://yvibojnl.esy.es");
- }
- else
- {
- print '<script type="text/javascript">';
- print 'alert("';
- print 'Error updating record';
- print '")';
- print '</script>';
- }
- }
- if (isset($_POST['editdata']))
- {
- $editID = $_POST['ID'];
- $editno = $_POST['no'];
- $company = $_POST['company'];
- $product = $_POST['product'];
- $founder = $_POST['founder'];
- $website = $_POST['website'];
- $tel = $_POST['tel'];
- $email = $_POST['email'];
- $sql = "SELECT * FROM nef WHERE ID='$editID'";
- //$sql = $conn->query("UPDATE nef SET Product='$product' WHERE ID='$editID'");
- //$sql2 = "UPDATE nef SET No='$editno', Company='$company', Product='$product', Founder='$founder', Website='$website', Tel='$tel', Email='$email' WHERE ID='$editID'";
- $result = $conn->query($sql);
- $row = $result->num_rows;
- if ($row)
- {
- $sql2 = "UPDATE nef SET Company='$company', Product='$product', Founder='$founder', Website='$website', Tel='$tel', Email='$email' WHERE ID='$editID'";
- $result = $conn->query($sql2);
- $sql = "SELECT * FROM nef WHERE ID='$editID'";
- $result = $conn->query($sql);
- if ($row)
- {
- $abc = $result->fetch_assoc();
- }
- header("Location: http://yvibojnl.esy.es");
- //print '<script type="text/javascript">';
- //print 'alert("';
- //print 'shit';
- //print '")';
- //print '</script>';
- }
- else
- {
- //print '<script type="text/javascript">';
- //print 'alert("';
- //print $editID;
- //print $editno;
- //print $editcompany;
- //print $editproduct;
- //print $editfounder;
- //print $editwebsite;
- //print $edittel;
- //print $editemail;
- //print 'Error: Please choose row first. (Connection Error)';
- //print '")';
- //print '</script>';
- }
- }
- if (isset($_POST['deletedata']))
- {
- $deleteID = $_POST['ID'];
- $sql = "DELETE FROM nef WHERE ID='$deleteID'";
- $conn->query($sql);
- header("Location: http://yvibojnl.esy.es");
- }
- //print_r ($array);
- //echo $company;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement