Thursday, 3 March 2016

27/01/16 - BENGKEL PHP Hypertext Preprocessor


Pengajar : Encik Faisal & Pn. Nornima

Aktiviti : 


  1. Belajar basic tentang PHP.
  • Introduction to PHP
  • PHP Fundamental
  • Variables, Dta Types, Operators.
  • Conditional Statements
  • Loops
  • Functions
  • Arrays
  • Forms
  • PHP & MySql2. 

      2. Buat exercise dalam kumpulan

Ahli kumpulan: Saya, Aina & Azrul
Soalan :
Tugasan yg diberikan
Jawapan:

a. Create new customer


<html>
<body>

<h2> <center> NEW CUSTOMER REGISTER </center></h1>
<div align="center">
<form method="POST" action="form_insert.php">
  <table width="200" border="2">
    <tr>
      <td scope="col">Name</th>
      <td scope="col">:</th>
      <td colspan="2" scope="col">
        <label for="textfield"></label>
        <input type="text" name="cust_name" onfocus="this.value = '';" onblur="if (this.value == '') " required="required" />
      </form></th>
    </tr>
 
    <tr>
      <td colspan="4">
        <div align="center">
          <input type="submit" name="button" id="button" value="Submit" />
          </div>
      </form></td>
    </tr>
  </table>
</div>

</form>
</body>
</html>

b. Customer List

<html>
<body>
<?php
include ('connection.php');
?>
<html>
<body>

<table width="411" height="79" border="1" cellspacing="0" align="center">
<tr>
<th width="49" bgcolor="#FFCC99">id</th>
<th width="80"   bgcolor="#FFCC99">Name</th>
<th width="99"  bgcolor="#FFCC99">Action</th>
</tr>


<?php
$sql = "SELECT cust_id, cust_name FROM cust_profile";
$result = $con->query($sql);

if ($result->num_rows > 0) {

while($row = $result->fetch_array()) {
echo "<tr><td>" . $row["cust_id"]. "</td><td>" . $row["cust_name"]."</td>";
echo "<td> <a href='edit_customer.php?cust_id=". $row["cust_id"]."'>edit </a>  || <a href='delete_cust.php?cust_id=". $row["cust_id"]."'>delete </td></tr>";
}
echo "</table>";
}
else {
     echo "0 results";
}

$con->close();
?>

<div align="center"><a href="new_customer.php">Home</a>
</div>


</body>
</html>

c. Edit Customer

<?php
 include('connection.php');

 $result=0;
$cust_id=$_GET['cust_id'];
$query= "SELECT cust_id, cust_name FROM cust_profile WHERE cust_id=$cust_id";
$result=$con->query($query);
echo count($result);

while($dataArray = $result->fetch_array()){

$id = $dataArray['cust_id'];
$name= $dataArray['cust_name'];

echo "$id: $name<br/>";


}

?>

<html>
<body>


<h2> <center> Edit CUSTOMER REGISTER </center></h1>
<div align="center">
<form method="POST" action="form_edit.php?cust_id=<?= $cust_id;?>]">
  <table width="200" border="2">
    <tr>
      <td scope="col">Name</th>
      <td scope="col">:</th>
      <td colspan="2" scope="col">
        <label for="textfield"></label>
<input type="hidden" name="cust_id" id="cust_id" value="<?php echo $row["userid"]; ?>" />
        <input type="text" name="cust_name" value="<?php echo $name; ?>" />
      </form></th>
    </tr>
 
    <tr>
      <td colspan="4">
        <div align="center">
          <input type="submit" name="button" id="button" value="Submit" />
          </div>
      </form></td>
    </tr>
  </table>
</div>

</form>
</body>
</html>


d. Delete Customer


<?php
include('connection.php');

 $cust_id=$_GET['cust_id'];
$query =" DELETE FROM cust_profile WHERE cust_id=$cust_id";
$result= $con->query($query);

if($result)
echo 'Data already deleted: '.$con->affected_rows;
else
die('There wan an error running in the query [' .$con->error . '] ');

$con->close();
header('Location: cust_list.php');
?>





0 comments:

Post a Comment

 

Olala Template by Ipietoon Cute Blog Design and Bukit Gambang