para sa add
<?php include 'template-parts/header.php' /** calling of header(to make it uniform in all template file) **/?>
<div class="container home">
<h3> Create New Student </h3>
<?php
include 'connection.php'; /** calling of connection.php that has the connection code **/
if( isset( $_POST['create'] ) ): /** A trigger that execute after clicking the submit button **/
/*** Putting all the data from text into variables **/
$fname = $_POST['fname'];
$mname = $_POST['mname'];
$lname = $_POST['lname'];
$addr = $_POST['addr'];
$gender = $_POST['gender'];
$course = $_POST['course'];
$year = $_POST['year'];
$section = $_POST['section'];
mysql_query("INSERT INTO student_record(fname,mname,lname,addr,gender,course,year,section)
VALUES('$fname','$mname','$lname','$addr','$gender','$course','$year','$section')")
or die(mysql_error()); /*** execute the insert sql code **/
echo "<div class='alert alert-info'> Successfully Saved. </div>"; /** success message **/
endif;
?>
<form action="" method="POST">
<label> Full Name: </label>
<input type="text" placeholder="First Name" class="input-medium" name="fname" />
<input type="text" placeholder="Middle Name" class="input-medium" name="mname" />
<input type="text" placeholder="Last Name" class="input-medium" name="lname"/>
<label> Address: </label>
<textarea class="span7" name="addr"></textarea>
<label> Gender: </label>
<select class="span2" name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<label> Course you want to enroll: </label>
<input type="text" placeholder="Enter the complete course name" class="input-xxlarge" name="course" />
<label> Year and Section </label>
<input type="text" placeholder="Year" class="input-medium" name="year"/>
<input type="text" placeholder="Section" class="input-medium" name="section"/>
<br />
<input type="submit" name="create" value="Create New Student" class="btn btn-info" />
</form>
</div>
</div>
</body>
</html>
para sa view
<div class="container home">
<h3> Read all the student profile </h3>
<?php include "connection.php" /** calling of connection.php that has the connection code **/ ?>
<table class="table table-bordered">
<thead>
<tr>
<th width="60px">Stud ID</th>
<th>Full Name</th>
<th>Address</th>
<th>Gender</th>
<th>Course, Year and Section</th>
</tr>
</thead>
<tbody>
<?php
$result = mysql_query("SELECT * FROM student_record");
while($data = mysql_fetch_object($result) ):
?>
<tr>
<td><?php echo $data->ID ?></td>
<td><?php echo $data->fname." ".$data->mname." ".$data->lname ?></td>
<td><?php echo $data->addr?></td>
<td><?php echo $data->gender?></td>
<td><?php echo $data->course." ".$data->year." ".$data->section ?></td>
</tr>
<?php
endwhile;
?>
</tbody>
</table>
</div>
</div>
</body>
</html>
Visit mo nlang to para mas ma igi. Downloadable yung code sa article.
http://www.codeinquirer.com/simple-crud-in-php-and-mysql-add-edit-delete-view-in-php-and-mysql/