<?php
$empno=$_GET['id'];
//database connect
$db=mysqli_connect("localhost","root","","mycompanyhr");
// database connection
if ($db==false) {
echo "Connect failed: ". mysqli_connect_error($db);
exit();
}
else {
echo "Connection successful";
}
$sql1="select * from employee where EMPNO='$empno' ";
$rs1=mysqli_query($db,$sql1);
//fetch all data
$record=mysqli_fetch_array($rs1);
$fname=$record['FIRSTNAME'];
$lname=$record['LASTNAME'];
$dept=$record['WORKDEPT'];
$phone=$record['PHONENO'];
?>
Update record
<form name='forminsert' method='get' action=''>
Employee no
<input name='txtempno' type='text' maxlength=6
value='<?php echo $empno;?>' > <br>
Firstname
<input name='txtfname' type='text'
value='<?php echo $fname;?>' > <br>
Lastname
<input name='txtlname' type='text'
value='<?php echo $lname;?>' > <br>
Department
<input name='txtdept' type='text'
value='<?php echo $dept;?>' > <br>
Extension
<input name='txtphone' type='text'
value='<?php echo $phone;?>' > <br>
<input name='submit' type='submit' value='Save'> <br>
</form>
<?php
//extract all info from the form
$empno=$_GET['txtempno'];
$fname=$_GET['txtfname'];
$lname=$_GET['txtlname'];
$dept=$_GET['txtdept'];
$phone=$_GET['txtphone'];
//develop the SQL command
if($empno!=''){
$sql="update employee
set FIRSTNAME='$fname', LASTNAME='$lname',
WORKDEPT='$dept', PHONENO='$phone'
where EMPNO='$empno' ";
//execute the SQL command
$rs=mysqli_query($db,$sql);
//check the execution status
if($rs==false){
echo "Record cannot be saved!<br>";
echo "SQL Error : ".mysqli_error($db);
}
else{
echo "<br>Record for $fname update!<br>";
echo "<a href='listing-edit.php'>
List records</a><br>";
}
}//end NULL
?>
Scenario You are given a task to develop a simple web database application for a movies rental shop. The system will store the information of all the movies available in the shop. Below are the information needed for the database. Database server information : server address= localhost , username= root , no password Database name: MOVIEDB This is the database source Table name : Movies Fields in table Movies : MovieID , MovieTitle , Category , Director , YearProduced , RentalPrice . Tasks 1. Create the database and table as stated above (using MySQL through phpMyAdmin). Populate the database by entering at least 5 movie titles. 2. Develop the web pages (combination of HTML and PHP scripts) to search and display the movies information by MovieTitle and YearProduced . 3. Develop a HTML form for the user to insert a new record of a new movie. Prepare the input for Category and YearProduced using the select option list. The categories are fiction , horror , comedy , ...
Comments
Post a Comment