2.signup.php


<?php
define("DB_SERVER","localhost");
define("DB_USER","root");
define("DB_PWD","");
define("DB_NAME","personal_db");
            //steps
            //1.Store data to the variables
    $name=$_POST['name'];
    $birth_month=$_POST['birth_month'];
    $birth_day=$_POST['birth_day'];
    $birth_year=$_POST['birth_year'];
    $address=$_POST['address'];
    $contactno=$_POST['contactno'];
    $email=$_POST['email'];
            //2.connect to the database
            $db=connect_db();
            //3.create sql statement
            $sql="INSERT INTO members(
                                                            name,
                                                            birth_month,
                                                            birth_day,
                                                            birth_year,
                                                            address,
                                                            contactno,
                                                            email)VALUES(
                                                            '$name',
                                                            '$birth_month',
                                                            '$birth_day',
                                                            '$birth_year',
                                                            '$address',
                                                            '$contactno',
                                                            '$email')";
            //4.execute sql statement specifying the current connection                                               
            $result=mysql_query($sql,$db);
           
            //5.display message
            if($result){
                        header('location:/personalwebsite.com/views/message_view.php');
            }          
            function connect_db(){
                        $con=mysql_connect(DB_SERVER,DB_USER,DB_PWD);
                        if(!$con){die("Error: ".mysql_error());}
                        $db_select=mysql_select_db(DB_NAME,$con);
                        if(!$db_select){die("Error: ".mysql_error());}
                        return $con;
            }
?>

No comments:

Post a Comment