Jump to content

how to check entries exist in mysql database or not?


vinod_vsd

Recommended Posts

<?php  

$where="";

if(isset($_POST['courier_no']))

{

$var2 = explode(",",$var);

 

$where=" AND A.courier_no= ". $_POST['courier_no'];

}

?> // here i get courier_no. and i want to display details if no exist in daatabase..

please help in this regards

 

$sql=("SELECT A.courier_id, A.courier_no , A.sender_name ,A.saddress,

B.location_name AS Sender_location  ,

    A.reciever_name ,A.raddress ,

C.location_name  AS Reciever_location

FROM  courier_detail A,location B,location  C 

        WHERE A.location2 = B.location_id AND

            A.location_id = C.location_id AND A.isdelete=0 ".$where) ; // using this query i want to display record set .

$result =mysql_query($sql);

while($row = mysql_fetch_array($result))

  {

                          // here i fetch all details

                        }

Link to comment
Share on other sites

<form action="courier_list.php" method="post" >

      <table cellpadding="0" cellspacing="0" border="0" style="margin:15px 0 0 35px" >

  <tr>

  <td width="147" style="height:19px"><label for="Serach">

  <input  type="text" name="courier_no" id="courier_no" style="width:133px; height:19px; border-style:double; border-width:1px; border-color:#AFAFAF" value="Search Your Tracking ID"></label>

  </td>

  <td width="55" style="height:19px"><input type="image" name="submit" src="images/search.jpg" ></td>

  </tr>

</table></form> <!--- from here i send courier_no to courier_list.php

Link to comment
Share on other sites

I will post the code that was pm'ed to me for other to see:

 

<?php include("top.php");?>
   <?php                     
$where="";
if(isset($_POST['courier_no']))
{
$var=$_POST['courier_no'];
   
$where=" AND A.courier_no LIKE '". $_POST['courier_no'] ."%'";
}
?>
   <tr>
    <td class="content" valign="top">
         <table width="100%" border="0" align="right">
         <tr bordercolordark="#FF0000">
         <td align="center" colspan="2">
         <h2 align="center"><font color="#FF0033" size="5" face="Courier New">Your Courier Details</font></h2>
         </td>
         </tr>
         <table width="99%" align="right" style="border:solid 1px" class="nav_sel">
         <?php include("connect.php"); ?>
         <?php  
         $courier_id=0;
          $sql=("SELECT A.courier_id, A.courier_no , A.sender_name ,A.saddress,
                           B.location_name AS Sender_location  ,
                            A.reciever_name ,A.raddress ,
                           C.location_name  AS Reciever_location
                           FROM  courier_detail A,location   B,location  C
                             WHERE A.location2 = B.location_id AND
                                A.location_id = C.location_id AND A.isdelete=0 ".$where) ; 
               $result =mysql_query($sql);              
         while($row = mysql_fetch_array($result))
           {
       $courier_id=$row['courier_id'];
           echo "<tr>";
         echo"<td height='31' colspan='1' align='center'><b>Courier No :</b></td>";
         echo"<td width='117' colspan='0'  bgcolor='#dce4ff'>". $row['courier_no'] ."</td>";
         echo "<td width='117'  height='29'></td>";
         echo "<td colspan='0' height='30' bgcolor='#dce4ff'></td>";
         echo "</tr>";
         echo "<tr>";            
         echo "<td width='100' height='34'><b> Sender Name :</b></td>";
         echo "<td width='117' bgcolor='#dce4ff'>". $row['sender_name'] ."</td>";
         echo "<td width='110'> <b>Reciever Name :</b></td>";
         echo "<td width='117'  bgcolor='#dce4ff'>". $row['reciever_name'] ."</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<td height='29'><b>Sender Address :</b></td>";
         echo "<td  bgcolor='#dce4ff'>". $row['saddress'] ."</td>";
         echo "<td><b>Reciever Address :</b></td>";
         echo "<td  bgcolor='#dce4ff'>". $row['raddress'] ."</td>";
         echo "</tr>";
         
         echo "<tr>";            
         echo "<td height='29' width='135'><b>Sender Location :</b></td>";
         echo "<td width='70'  bgcolor='#dce4ff'>". $row['Reciever_location'] ."</td>";
         echo "<td width='135'><b>Reciever Location :</b></td>";
         echo "<td  bgcolor='#dce4ff'>". $row['Sender_location'] ."</td>";
         echo "</tr>";
          ?>
         <?php 
         echo "</td >" ;
         echo "</tr>";
         }
         
         echo "</table>";?><br />
            <h2 align="center"><font color="#FF0000" size="5" face="Courier New">Courier Tracking Details</font></h2>
         <table width="99%" border="0"align="right" style="border:solid 1px" class="nav_sel">
         
            <?php  
               
         $sql ="SELECT A.remark, A.recieve_date, A.transit_id, 
                        B.location_name AS Forward_To, D.type_name AS Courier_Type,E.courier_no AS Courier_No,
                        C.status_name AS Status 
                        FROM transit A, location B,STATUS C,TYPE D,courier_detail E
                        WHERE A.location_id = B.location_id
                        AND A.status_id = C.status_id
                        AND A.type_id = D.type_id 
                        AND A.courier_id=E.courier_id AND E.courier_id=".$courier_id." order by recieve_date asc";
         $result1 =mysql_query($sql); 
         
         while($row1 = mysql_fetch_array($result1))
           {
         
           echo "<tr>";
         echo "<td width='110'  height='29'><b>Status :</b></td>";
         echo "<td width='117' bgcolor='#dce4ff'>". $row1['Status'] ."</td>";
         echo "<td width='117'  height='29'><b>Recieve Date :</b></td>";
         echo "<td width='117' bgcolor='#dce4ff'>". $row1['recieve_date'] ."</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<td width='117'  height='29'><b>Forward Towards :</b></td>";
         echo "<td width='70' bgcolor='#dce4ff'>" . $row1['Forward_To'] ."</td>";            
         echo "<td width='117'  height='29'><b>Courier Type :</b></td>";
         echo "<td bgcolor='#dce4ff'>". $row1['Courier_Type'] ."</td>";
         echo "</tr>";
         echo "<tr>";            
         echo "<td width='117'  height='29'><b>Remark :</b></td>";
         echo "<td colspan='0' height='30' bgcolor='#dce4ff'>". $row1['remark'] ."</td>";
         echo "<td width='117'  height='29'></td>";
         echo "<td colspan='0' height='30' bgcolor='#dce4ff'></td>";
         echo "</tr>";
         
         ?>
         <?php 
         echo "</td >" ;
         echo "</tr>";
         }
         
         
         echo "</table>";?>
         <?php mysql_close($con);
      }
         ?>

         
    </td>

<?php include("footer.php"); ?> ///////// the whole file is my courier_list.php

 

add some debugging to your script to see what is happening:

 

$sql = "SELECT A.courier_id, A.courier_no , A.sender_name ,A.saddress,
B.location_name AS Sender_location  ,
A.reciever_name ,A.raddress ,
C.location_name  AS Reciever_location
FROM  courier_detail A,location   B,location  C
WHERE A.location2 = B.location_id AND
A.location_id = C.location_id AND A.isdelete=0 ".$where; 
$result = mysql_query($sql) or die($sql . '<br />' . mysql_error());

 

1. the parenthesis should be removed from the actual SQL.

 

2. run that snippet and post the results.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.