Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index.php
- <?php
- $name = $address = $email = "";
- $nameErr = $addressErr = $emailErr = "";
- If($_SERVER["REQUEST_METHOD"] == "POST"){
- if(empty ($_POST ["name"])){
- $nameErr = "name is required!";
- }else{
- $name = $_POST["name"];
- }
- if(empty ($_POST ["address"])){
- $addressErr = "address is required!";
- }else{
- $address = $_POST["address"];
- }
- if(empty ($_POST ["email"])){
- $emailErr = "email is required!";
- }else{
- $email = $_POST["email"];
- }
- }
- ?>
- <style>
- .error{
- color: red;
- }
- </style>
- <form method="post" action="<?php htmlspecialchars("PHP_SELF");?>">
- <input type="text" name="name" value=""><br>
- <span class="error"><?php echo $nameErr; ?></span><br>
- <input type="text" name="address" value=""><br>
- <span class="error"><?php echo $addressErr; ?></span><br>
- <input type="text" name="email" value=""><br>
- <span class="error"><?php echo $emailErr; ?></span><br>
- <input type="submit" value="submit">
- </form>
- <hr>
- <?php
- include("connections.php");
- if($name && $address && $email) {
- $query = mysqli_query($connections, "INSERT INTO mytbl(name,address,email) VALUES('$name','$address','$email') ");
- echo "<script language='javascript'>alert('New Record Has been Inserted!')</script>";
- echo "<script> window.location.href='index.php';<script>";
- }
- $view_query = mysqli_query($connections, "SELECT * FROM mytbl");
- echo "<table border = '1' width = '50%'>";
- while($row = mysqli_fetch_assoc ($view_query)) {
- $db_name = $row["name"];
- $db_address = $row["address"];
- $db_email = $row["email"];
- echo "<tr>
- <td>$db_name</td>
- <td>$db_address</td>
- <td>$db_email</td>
- </tr>";
- }
- echo "</table>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement