4. Data Insert

  1. Method
    obviously have to put this code in fresh.php. where have your database connect.

    public function Insert($table,$id,$name,$email,$phone,$address){
           $query = mysqli_query($this->connect, "INSERT INTO $table SET id='$id', name='$name', email='$email', phone='$phone', address='$address'");
           if(mysqli_affected_rows($this->connect)>0){
               return true;
           }
           else{
               return false;
           }
       }
    

  2. create insert.php file

<?php
include("fresh.php");
if (isset($_REQUEST['submit'])) {
    //print_r($_REQUEST);
    extract($_REQUEST);
    if ($obj->Insert("members", $id, $name, $email, $phone, $address)) {
        header('location:tabulize_data.php'); // Where have your data show
    } else {
        $err_msg = "No Data Insert in Your table";
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Show Database</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    </head>

    <body>
        <div style="width: 700px; margin: 0 auto">
            <!-- ternary operators -->
            <?php
            echo (isset($err_msg)) ? $err_msg : "";
            ?>
            <form>
                <table class="table table-bordered table-hover" style="text-align: center;">  
                    <tr>
                        <td colspan="2">Insert Your Information</td>
                    </tr>
                    <tr>
                        <td>Id</td>
                        <td><input name="id" class="form-control" type="text" ></td>
                    </tr>
                    <tr>
                        <td>Name</td>
                        <td><input name="name" class="form-control" type="text" placeholder="Enter Your Name" required="required"></td>
                    </tr>
                    <tr>
                        <td>E-mail</td>
                        <td><input name="email" class="form-control" type="text" placeholder="Enter Your valid Email" required="required"></td>
                    </tr>
                    <tr>
                        <td>Phone</td>
                        <td><input name="phone" class="form-control" type="text" placeholder="Enter Your Number" required="required"></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td><textarea name="address" class="form-control"></textarea></td>
                    </tr>  
                    <tr>
                        <td colspan="2" align="center"><input type="submit" value="Save" name="submit" class="btn btn-primary"></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>

Insert form look like following screenshot:
insert-form

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s