Wednesday, October 3, 2018

Search a Record With No Record Found Checking in PHP and MySQL

In this article I improve my previous code in search a record in PHP and MySQL I included no record found if the person ID does not exist from the database. I just use JavaScript to accomplish the functionality that I want. I hope you will find my work useful.  Thank you.

 I am currently accepting programming work, it projects, school 

programming projects, thesis and capstone projects, IT consulting 

work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

My personal website is http://www.jakerpomperada.com




Sample Program Output

Program Listing

index.php

<html>
<?php
// Created By Mr. Jake R. Pomperada, MAED-IT
// Date : October 3, 2018
// Location : Bacolod City, Negros Occidental Philippines
// www.jakerpomperada.com

error_reporting(0);
?>
<style>
body {
    font-family: arial;
    font-size: 15px; 
}
</style>
<body>
<?php
$no_record ="";
    $search_me = $_POST['name']; 
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("users", $con);
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}


if (isset($_POST['name'])) {
mysql_select_db("users", $con);

$result = mysql_query("select * from accountdtl where account_no='$search_me'");
 if(mysql_num_rows($result) > 0) {
while($rowval = mysql_fetch_array($result))
 {
$accountnumber= $rowval['account_no'];
$title= $rowval['title'];
$fname= $rowval['fname'];
$lname= $rowval['lname'];
$add1= $rowval['address1'];
$add2= $rowval['address2'];
$town= $rowval['town'];
$country= $rowval['country'];
$pin= $rowval['pcode'];
$mob= $rowval['con_no'];
$mailid= $rowval['mail_id'];
$uname= $rowval['uname'];
$balance= $rowval['balance'];
}
}  

else {
         
   $no_record = "<script>alert('No ID Record Found. Try Again')</script>";
        $accountnumber= "";
$title= "";
$fname= "";
$lname= "";
$add1= "";
$add2="";
$town= "";
$country= "";
$pin= "";
$mob= "";
$mailid= "";
$uname= "";
$balance= "";  
        
    }
mysql_close($con);
}

?>

<form action="" method="post">

   <table style="color:purple;border-style:groove; height:150px;width:350px">
            <tr>
                <td style=" height:25px; font-family:'Copperplate Gothic Bold'">&nbsp;</td>
            </tr>
            <tr>
                <td style="color:blue;background-color:aqua;height:25px">Enter Account no&nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="name" id="name" 
                  value='<?php echo  $accountnumber; ?>'
                    type="text" autofocus/></td>
            </tr>
            <tr>
                <td style="height:25px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Submit" style="color:white;background-color:brown; height:30px" /></td>
            </tr>
        </table>
    </form>



  <table  style="color:purple;border-style:groove; height:150px;width:350px" background="3.jpg">
        <tr>
            
            <td style="font-family:Copperplate Gothic Bold">&nbsp;</td>
        </tr>
        <tr>
            <td style="color:blue;background-color:aqua;" class="auto-style3">Account no:</td>
            <td class="auto-style4">
                <input id="Text1" type="text" value='<?php echo  $accountnumber; ?>' 
                size="50"/></td>
        </tr>
        <tr>
            <td style="color:blue;background-color:aqua;" class="auto-style3">Title</td>
            <td class="auto-style4">
                <input id="Text2" type="text" value='<?php echo  $title; ?>'
                size="50"/></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">FirstName:</td>
            <td class="auto-style4">
                <input id="Text3" type="text" value='<?php echo  $fname; ?>'
                size="50" /></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">Surname:</td>
            <td class="auto-style4">
                <input id="Text4" type="text" value='<?php echo  $lname; ?>'
                size="50"  /></td>
        </tr>
        <tr>
            <td style="color:blue;background-color:aqua;" class="auto-style3">Address Line 1:</td>
            <td class="auto-style4">
                <input id="Text5" type="text" value='<?php echo  $add1; ?>'
                size="50"  /></td>
        </tr>
        <tr>
           <td style="color:blue;background-color:aqua;" class="auto-style3">Address Line 2:</td>
            <td class="auto-style4">
                <input id="Text6" type="text" value='<?php echo  $add2; ?>'
                size="50"  ></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">Town:</td>
            <td class="auto-style4">
                <input id="Text7" type="text" value='<?php echo  $town; ?>'
                size="50" /></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">Country:</td>
            <td class="auto-style4">
                <input id="Text8" type="text" value='<?php echo  $country; ?>'
                size="50"  /></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">Post Code:</td>
            <td class="auto-style4">
                <input id="Text9" type="text"  value='<?php echo  $pin; ?>' 
                size="50"/></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">Contact Number:</td>
            <td class="auto-style4">
                <input id="Text10" type="text" value='<?php echo  $mob; ?>' 
                size="50" /></td>
        </tr>
        <tr>
            <td style="color:blue;background-color:aqua;" class="auto-style3">Email Address:</td>
            <td class="auto-style4">
                <input id="Text11" type="text" value='<?php echo  $mailid; ?>'
                size="50" /></td>
        </tr>
        <tr>
             <td style="color:blue;background-color:aqua;" class="auto-style3">User Name:</td>
            <td class="auto-style4">
                <input id="Text12" type="text" value='<?php echo  $uname; ?>'
                 size="50" /></td>
        </tr>
        <tr>
            <td style="color:blue;background-color:aqua;" class="auto-style3">Balance:</td>
            <td class="auto-style4">
                <input id="Text13" type="text" value='<?php echo  $balance; ?>'
                size="50" /></td>
        </tr>
        <tr>
            <td></td>
        </tr>
    </table>
<?php echo $no_record; ?> 
</form>

</body>
</html>

accountdtl.sql

-- phpMyAdmin SQL Dump
-- version 4.8.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Oct 02, 2018 at 02:04 PM
-- Server version: 10.1.34-MariaDB
-- PHP Version: 5.6.37

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `users`
--

-- --------------------------------------------------------

--
-- Table structure for table `accountdtl`
--

CREATE TABLE `accountdtl` (
  `id` int(11) NOT NULL,
  `account_no` varchar(100) NOT NULL,
  `title` varchar(200) NOT NULL,
  `fname` varchar(200) NOT NULL,
  `lname` varchar(200) NOT NULL,
  `address1` varchar(200) NOT NULL,
  `address2` varchar(200) NOT NULL,
  `town` varchar(200) NOT NULL,
  `country` varchar(200) NOT NULL,
  `pcode` varchar(200) NOT NULL,
  `con_no` varchar(200) NOT NULL,
  `mail_id` varchar(200) NOT NULL,
  `uname` varchar(200) NOT NULL,
  `balance` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `accountdtl`
--

INSERT INTO `accountdtl` (`id`, `account_no`, `title`, `fname`, `lname`, `address1`, `address2`, `town`, `country`, `pcode`, `con_no`, `mail_id`, `uname`, `balance`) VALUES
(1, '12345', 'Mr.', 'Juan', 'Sanchez', 'Old Sagay, Sagay City', 'Negros Occidental, Philippines ', 'Proper Sagay', 'Philippines', '4563', '123456', '123456', '121212', '12121212'),
(2, '123', 'Mrs.', 'Linda', 'Zamora', 'Bago City', 'Negros Occidental', 'Poblacion Proper', 'Republic of the Philippines', '1212', '343434', '343434', '343434', '34343434');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `accountdtl`
--
ALTER TABLE `accountdtl`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `accountdtl`
--
ALTER TABLE `accountdtl`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;




No comments:

Post a Comment