Advanced Web Development 1 (ITE232)- How to ADD records inside MySQL Database


loveIT

Untitled

Steps:

1.Connection to Database

2.Create Field Variables

3.Create the Query (INSERT command)

4.Send the query to the database

5.Display success message and/or error message

Example:

<?php
//Database Connection
include’db_connection.php’;

//Create the field variables
$id=$_POST[‘id’];
$fname=$_POST[‘fname’];
$lname=$_POST[‘lname’];
$month=$_POST[‘month’];
$day=$_POST[‘day’];
$year=$_POST[‘year’];
$age=$_POST[‘age’];
$gender=$_POST[‘gender’];
$course_id=$_POST[‘courses’];
//Query
$query=”INSERT into tbl_record (id,fname,lname,month,day,year,age,gender,course_id) VALUES(‘$id’,’$fname’,’$lname’,’$month’,’$day’,’$year’,’$age’,’$gender’,’$course_id’)”;
//Display a message
if(mysql_query($query))
{
echo


open(‘../index.php’,’_self’);

“;
}
else
{
echo mysql_errno().”:”.mysql_error();
}

?>

View original post

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