CREATE TABLE `tbl_member` ( `tbl_member_id` INT(11) NOT NULL, `first_name` VARCHAR(100) NOT NULL, `last_name` VARCHAR(100) NOT NULL, `contact_number` VARCHAR(100) NOT NULL, `email` VARCHAR(100) NOT NULL, `address` VARCHAR(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<?php $conn = new PDO('mysql:host=localhost; dbname=contact_info','root', ''); ?>
<form method="post" action="add_person_query.php"> <table border="1" cellspacing="5" cellpadding="5" width="100%"> <tr> <td> </td> <td width="395px"> <input type="text" class="text_Box" name="first_name" autofocus="autofocus" placeholder="First Name ....." required /> </td> </tr> <tr> <td> </td> <td width="395px"> <input type="text" class="text_Box" name="last_name" placeholder="Last Name ....." required /> </td> </tr> <tr> <td> </td> <td width="395px"> <input type="text" class="text_Box" name="contact_number" placeholder="Contact Number ....." required /> </td> </tr> <tr> <td> </td> <td width="395px"> <input type="email" class="text_Box" name="email" placeholder="Email ....."> </td> </tr> <tr> <td> </td> <td width="395px"> <input type="text" class="text_Box" name="address" placeholder="Address ....." required /> </td> </tr> <tr> <td colspan="2"> <a style="margin-right:70px;"> <button type="submit" class="btn_confirm"> Save Data </button> </a> <a href="index.php"> <button type="submit" class="btn_cancel"> Cancel </button> </a> </td> </tr> </table> </form>
<?php include ('db.php'); $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $contact_number=$_POST['contact_number']; $email=$_POST['email']; $address=$_POST['address']; $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO tbl_member (first_name, last_name, contact_number, email, address ) VALUES ('$first_name', '$last_name', '$contact_number', '$email', '$address')"; echo "<script>alert('Successfully Added!'); window.location='index.php'</script>"; ?>
<table border="1" cellspacing="5" cellpadding="5" width="100%"> <thead> <tr> </tr> </thead> <tbody> <?php require_once('db.php'); $result = $conn->prepare("SELECT * FROM tbl_member ORDER BY tbl_member_id ASC"); $result->execute(); for($i=0; $row = $result->fetch(); $i++){ $id=$row['tbl_member_id']; ?> <tr> </tr> <?php } ?> </tbody> </table>