Anyone can help? Here is two search by radio button one is requirement type and another radio button is build. I want to search by requirement type or build but it doesn't work...anyone can help to solve this problem, im very stuck! I've been doing this for two days.. I need to submit this code before 5pm today :'(((
<?php

include'Database.php';

?> <!Doctype html> <html> <head> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script type="text/javascript">
    function requirementtype() {
    if(document.form.valueToSearch.value==''){
          alert("Please Choose Requirement Type");
          return false;
    }

    document.form.submit();
}

   </script> <body> <center> <ul> 
   <a  method="post" id="form" name="form" > 
   <table width="50%" border="0" align="center"> 
   <thead> 
   <div align="left" id="txtHint">
   </div> 

   <td width="10" align="left"> 
   </td> <td width="30" align="left" bgcolor="#99CCFF">
   <strong>
   <font size="3" face="Palatino Linotype, Book Antiqua, Palatino, serif">Search by Requirement Type:</font></strong>
   </td> 
   <br> 
   <td width="150" align="left" bgcolor="#99CCFF"> 
   <input type="radio" name="valueToSearch" id="valueToSearch" value="Desktop">Desktop
        <input type="radio" name="valueToSearch" id="valueToSearch" value="Laptop" />Laptop
         <input type="radio" name="valueToSearch" id="valueToSearch" value="Scanner" />Scanner
     </font> 
     </label> 
     </td> 
     <td width="10" align="left"> 
     </td> <td width="30" align="left" bgcolor="#99CCFF"><strong><font size="3" face="Palatino Linotype, Book Antiqua, Palatino, serif">Search by Building:</font></strong></td> 
     <td width="150" align="left" bgcolor="#99CCFF"> <input type="radio" name="buildvalueToSearch" id="valueToSearch" value="ha1">HA1
        <input type="radio" name="buildvalueToSearch" id="valueToSearch" value="ha2" />HA2
         <input type="radio" name="buildvalueToSearch" id="valueToSearch" value="ha3" />HA3
     </font> 
     </label> 
     </td> 
     </thead> 
     </table> 
     </center> 
     <br>
     <center> 
     <input type="submit" name="search" value="submit"> 
     </center> </table> 
     <?php

if(isset($_POST['search']))
{
    $valueToSearch = $_POST['requirementtype'  'build' ];
     $sql = "SELECT * FROM register LIKE requirementtype '%".$valueToSearch."%'";

    $res= mysqli_query($dbconfig, $sql);    
    $num_rows=mysqli_num_rows($res);
    if ($num_rows==0)
    echo"<div align=center><font color=red size=5><B>NO DATA EXIST.</B></div><br>";

?> 
<center> 
<p> 
<table class = "registration" id="daftar" width = "80%" border = "1" cellspacing = "1" cellpadding = "1"> 
<tr> 
<th>NO</th> 
<th>BUILDING</th> 
<th>USER</th> 
<th>POSITION</th> 
<th>SERIAL NUMBER</th> 
<th>DEPARTMENT</th> 
<th>TAGGING NUMBER</th> 
<th>DELIVERY DATE</th> 
<th>LOCATION</th> 
<th>REMARKS</th>
<th>ASSET STATUS</th> 
<th>REQUIREMENT TYPE</th> 
<th>EDIT</th> 
<th>DELETE</th> 
</tr>
<?php

                  $counter = 0;

                        while ($userRow=mysqli_fetch_assoc($res)) {

                             $ptb12 = $userRow['build'];
                            $ptb2 = $userRow['user'];
                            $ptb3 = $userRow['position'];
                            $ptb4 = $userRow['serialnumber'];
                            $ptb5 = $userRow['department'];
                            $ptb6 = $userRow['taggingno'];
                            $ptb7 =$userRow['deliverydate'];
                            $ptb8 = $userRow['location'];
                            $ptb9 = $userRow['remarks'];
                            $ptb10 = $userRow['assetstatus'];
                            $ptb11 = $userRow['requirementtype'];
                            $ptb13 = $userRow['id'];
                            $counter++;

                        ?> 
                        <tr> 
                        <td> <?php echo  "$ptb12";?></td> 
                        <td> <?php echo  "$ptb2";?></td> 
                        <td> <?php echo  "$ptb3";?></td> 
                        <td> <?php echo  "$ptb4";?></td> 
                        <td> <?php echo  "$ptb5";?></td> 
                        <td> <?php echo  "$ptb6";?></td> 
                        <td> <?php echo  "$ptb7";?></td> 
                        <td> <?php echo  "$ptb8";?></td> 
                        <td> <?php echo  "$ptb9";?></td> 
                        <td> <?php echo  "$ptb10";?></td> 
                        <td> <?php echo  "$ptb11";?></td> 
                        <td> <button><a href="edit.php?id=<?php echo $ptb12; ?>" class="edit_btn"  >Edit</a></button></td> 
                        <td> <button><a href="deletepc.php?id=<?php echo $ptb12; ?>">Delete</a></button></td> 
                        </td> 
                        </tr> 
                        <?php } ?> 
                        </table> 
                        </form> 
                        </p> 
                        </center> 
                        </center> 
                        <?php }?> 
                        </body> 
                        </head> 
                        </html>

Quite many issues here:

The following code is not valid:

$valueToSearch = $_POST['requirementtype'  'build' ];

You can not have two strings as an array index. They should be separated in i.e two variables like so:

$searchRequirementtype = $_POST['requirementtype'];
$searchbuild = $_POST['build'];

These two values should be escaped before used in a query (google for SQL injection)

The SQL statement is not valid. There is no WHERE clause in it and no field you want to search in. Maybe something like:

"SELECT * FROM register WHERE `requirementtype` LIKE '%".$searchRequirementtype."%'";

On line 15 there is a stray <ul> tag without its end tag and any <li> tags.

The end </head> tag is also in a completely wrong place (at the end of the body).

The anchor <a> tag on line 23 can not have a method attribute. Was it supposed to be a <form> tag?

The <div> element on line 19 is in wrong place (you probably intended to put it in the <td> element).
Many elements, that are obsolete in HTML5, are used in your code (like <center>, cellspacing etc). Decent editor or IDE should display all the warnings.

You are missing the tr tags in the first table.

I recommend also that you use CSS for design and get rid of all presentation markup in your HTML. Since you use Bootstrap everything is already ready for you in the framework.

Maybe you clean up the code first, it will then be easier to help. This code here does display nothing in the browser due to too many errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.