First create Database with name "College" and Table with name "Course" using GUI in phpMyAdmin.
===================================================
Table:
Course(CID INT AUTO_INCREMENT,
C_name varchar(20),
primary key (CID));
Save file with name "Course.php" ===>
<html>
<body>
<form action="" method="POST">
<h1>Insert new data in Course Table =======></h1>
<h1><table>
<tr>
<td><font size='5'>Course Name:</font></td><td> <input type="text" name="c_name" placeholder="Type Course name"></td>
</tr>
</table>
</h1>
<input type="submit" name="sub" value="Insert">
</form>
<?php
include('connection.php');
mysql_select_db('COllege');
$c_name = $_REQUEST['c_name'];
if(isset($_REQUEST['sub']))
{
if(!mysql_query("insert into course(C_name) values ('$c_name');"))
{
die("Query run unsuccessful and Data not inserted!!<br>Error ==> <font color='red'>".mysql_error());
}
else
{
echo "Query run successful and Data inserted.......";
}
echo "<font color='red' size='5'><br/>New Inserted Data : <br/></font><font color='black' size='5'>= = = = = = = = = = =</font><br>";
}
$sql = mysql_query('select * from course;');
$sql1 = mysql_query('select * from course;');
$dd_sql = mysql_query('select * from course;');
if(!$sql && !d_sql)
die('Select query not excecuted !!'.mysql_error());
else
{
$db_course = mysql_fetch_array($sql);
if($db_course[0]==0)
{
exit;
}
else
{
echo "<font color='green' size='5'>".$c_name."</font>";
echo "<center><table border='1'>
<tr>
<th> CID </th>
<th> C_name </th>
<th> Delete </th>
<th> Update </th>
</tr>";
while($db_course1 = mysql_fetch_array($dd_sql))
{
echo "<tr>
<td>".$db_course1['CID']."</td><td>".$db_course1['C_name']."</td></td>
<td>
<a href='Edit_Course.php?id=$db_course[CID]'><button name='delete_buttoon'>Delete</button></a>
</td>
<td>
<form name='f2' method='POST' action='Edit_Course.php'>
<input type='text' name='update_box' placeholder='Type new Course name'>
<input type='hidden' value='$db_course[CID]' name='id'>
<input type='submit' name='update' value='Update'>
</form>
</td>
</tr>";
}
echo "</table>";
}
}
?>
</body>
</html>
===================================================
Save file with name "Edit_Course.php" ===>
<?php
$var_update_button = $_REQUEST['update'];
$var_id = $_REQUEST['id'];
$var_update_value = $_REQUEST['update_box'];
include ('connection.php');
mysql_select_db('College');
if(isset($var_update_button))
{
$sql = mysql_query("update course set C_name='$var_update_value' where CID='$var_id';");
if(!$sql)
die("Can't update record".mysql_error());
else
header('location:Course.php');
}
else
{
$sql = mysql_query("delete from Course where CID='$var_id';");
if(!$sql)
die("Can't delete record".mysql_error());
else
header('location:Course.php');
}
?>
For more information visit our YouTube channel ⏩⏩⏩
https://www.youtube.com/channel/UCUXIKbhnJ1_FcPqXcJFwzGg
Like, Share and subscribe the video =====>
For detailed description watch this video ⏩⏩⏩
https://www.youtube.com/channel/UCUXIKbhnJ1_FcPqXcJFwzGg
Like, Share and subscribe the video =====>
Comments
Post a Comment