Skip to main content

Simplest PHP code to delete a record

image

Listing4delete.php

<html>
<head>
<title>Search by Name</title>
</head>
<body>
Search for name<br>
<form action="" method="get" name="formsearch">
Enter a name <input name="txtsearch" type="text">
<input name="btnsearch" type="submit" value="Search">
</form>
 
<?php
//to create the bridge
$db=mysqli_connect("localhost","root","","mycompanyhr");
 
//connection failed
if($db==false){//connection error
    echo("Connection failed : ". 
            mysqli_connect_error($db));
    exit();
}
//u are connected to db
else{
    echo("Connected to database <hr>");
}
 
$n=$_GET['txtsearch'];
//sql command to retrieve records
$sql="select * from employee
        where FIRSTNAME like '%$n%'";
 
//execute the sql command
$qr=mysqli_query($db, $sql);
 
 
//if there's any SQL error
if($qr==false){
    echo ("Query cannot be executed!<br>");
    echo ("SQL Error : ".mysqli_error($db));
}
//no SQL error, so display data
else{
    echo "<table border=1>";
    while($rekod=mysqli_fetch_array($qr)){
        echo "<tr>";
        echo "<td>".$rekod['EMPNO']."</td>";
        echo "<td>".$rekod['FIRSTNAME']."</td>";
        echo "<td>".$rekod['LASTNAME']."</td>";
        echo "<td>".$rekod['PHONENO']."</td>";
        echo "<td>".$rekod['JOB']."</td>";
        echo "<td> <a href='delete.php?id=".$rekod['EMPNO']."'> 
                delete </a> </td>";
        echo "<tr>";
    }
    echo "</table>";
}
?>
</body>
</html>

 


image


Delete.php



<?php
//extract info from id 
  $empno=$_GET['id'];
 
//develop the SQL command to delete record 
  $sql="delete from employee 
        where EMPNO='$empno'"; 
 
//database connection 
$db=mysqli_connect("localhost","root","","mycompanyhr"); 
 
  // checking database connection 
  if ($db==false) { 
    echo "Connect failed: ". mysqli_connect_error($db); 
    exit(); 
  } 
  else { 
    echo "Connection successful"; 
  } 
 
//execute the SQL command 
  $rs=mysqli_query($db,$sql); 
 
//check the execution status 
  if($rs==false){ 
    echo "Record cannot be deleted!<br>"; 
    echo "SQL Error : ".mysqli_error($db); 
  } 
  else{ 
    echo "<br>Record for $empno deleted!<br>"; 
    echo "<a href='listing4delete.php'> 
          Back to the list</a>"; 
  } 
?> 

Comments

Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – https://play.google.com/store/apps/details?id=net.kerul.peribahasa English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur http://books.google.com.my/books/about/Peribahasa_dan_ungkapan_Inggeris_Melayu.html?id=bgwwQwAACAAJ CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

WebDev

http://blog.kerul.net PHP DEVELOPMENT TOOLS Download the XAMPP latest version from www.apachefriends.org . This installation file contains the Apache web server, PHP 5 and 4 interpreter, and the MySQL 5 Community edition. - download latest version MozillaFireFox (OpenSource web browser firefox) – download latest version Google Chrome – fastest web browser on earcth – fast download chrome here TEACHING PLAN Download the teaching plan here for Web/Internet Programming ( download ) NOTES HTML references HTML Editor -  http://www.sublimetext.com/ Lab 1: HTML Basics -  http://www.w3schools.com/html/ Lab 2: Responsive Design:  http://www.w3schools.com/html/html_responsive.asp Lab 3: HTML Forms  http://www.w3schools.com/html/html_forms.asp Lab 4: HTML 5  http://www.w3schools.com/html/html5_intro.asp Lab 5: Bootstrap for responsive Web -  http://www.w3schools.com/bootstra

Contact Us at blog.kerul.net

Powered by EMF HTML Contact Form

Submit your blog address here

Create your own blog and send the address by submitting the comment of this article. Make sure to provide your full name, matrix and URL address of your blog. Refer to the picture below. Manual on developing a blog using blogger.com and AdSense, download here … Download Windows Live Writer (a superb offline blog post editor)

Lab quiz for Web Programming

Scenario You are given a task to develop a simple web database application for a computer shop. The system will store the information of all the branded laptops in the shop. Below are the information needed for the database. Database server information : server address= localhost , username= root , no password Database name: COMPUTERSHOP Table name : Laptops Fields in table Movies : CompID , CompModel , Manufacturer , Processor , RAMCapacity , HarddiskCapacity , Price . Tasks 1. Create the database and table as stated above (using MySQL through phpMyAdmin). 2. Develop the web page by using the combination of HTML and PHP scripts to search and display the laptop information by CompModel . (Create two different pages) 3. Develop a HTML form for the user to insert a record of a new laptop computer. Save the new record in the table Laptops . Send the code to me by 12pm, 25Feb 2009 , by email to khirulnizam@gmail.com …