Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: filter data using checkbox php and mysqli

  1. #11
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    You need to debug your final query. Unless you have changed anything since your first post, the query string appears to be built with these two lines of code:

    Code:
    $sql="SELECT * FROM ";
    .
    .
    .
    $sql .= " WHERE software_title LIKE '%software_title%' ";
    Which will result in the following query:

    Code:
    SELECT * FROM  WHERE software_title LIKE '%software_title%'
    That line has two obvious errors. Firstly there is no table-name in the query and secondly you are searching for any string which contains the characters software-title within it.

    You need to add a table-name in the first line and rewrite the second line so that the value contained in the PHP variable $software_title is used in place of the string software_title.

  2. #12
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Sorry I have gone a different way with it and using a text input field instead rather than text boxes but got one little issue, each time I load the page I get this notice

    Notice: Undefined index: search in /home/broadway/public_html/admin/product-keys-sold/search-by-software-title.php on line 53

    but as soon as I do a search, the notice disappears, below is the new coding I have

    Code:
    <form action="" method="post">
    <input type="text" name="search">
    <input type="submit" name="submit" value="Search">
    </form>
    
    <?php
    
    $servername = 'localhost';
    $username = 'dbuser';
    $password = 'dbpassword';
    $dbname = 'dbtable';
    
    $search_value= $_POST['search'];
    
    $con=new mysqli($servername,$username,$password,$dbname);
    
    if($con->connect_error){
        echo 'Connection Faild: '.$con->connect_error;
    	
        }else{
            $sql="select id, software_title, customers_email, DATE_FORMAT(date_purchased, '%d/%m/%Y') AS date_purchased, sent from product_keys_sold where software_title LIKE '%$search_value%' ORDER BY id";
    		
            $res=$con->query($sql);
    
    		// display records in a table
    echo "<table class='records'>";
    
    // set table headers
    echo "<tr>
    <th>ID</th>
    <th>Software Title</th>
    <th>Customers Email</th>
    <th>Date Purchased</th>
    <th>Sent</th>
    <th colspan='2'>Actions</th>
    </tr>";
    
            while($row=$res->fetch_assoc()){
    			echo "<tr>";
    echo "<td><a href='view-specific-product-keys-sold.php?id=" . $row['id'] . "'>".$row['id'] . "</a></td>";
    echo '<td>' . $row["software_title"]; '</td>';
    echo '<td>' . $row["customers_email"]; '</td>';
    echo '<td>' . $row["date_purchased"]; '</td>';
    echo '<td>' . $row["sent"]; '</td>';
    echo "<td><a href='add-update-keys-sold.php?id=" . $row['id'] . "'>Edit</a></td>";
    echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
    echo "</tr>";
    		}
    		
    		echo '</table>';
    
                }       
            
    ?>
    the form works perfect, just need to get rid of that notice, I know I have error reporting on and I know the notice will prob not show when I remove the error reporting but will be nice to get the coding right first

  3. #13
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    The code you have provided in your last post only contains 54 lines and line 53 is empty so the error must be elsewhere on your page.

  4. #14
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by styxlawyer View Post
    The code you have provided in your last post only contains 54 lines and line 53 is empty so the error must be elsewhere on your page.
    Sorry might be because I not post all the other coding as was HTML and not relevant, in my php file line 53 is the following


    $search_value= $_POST['search'];

  5. #15
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Sorry have solved the issue now

  6. #16
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Sorry found another issue, the search form is returning fields that does not even have the text in the database record so really confused why the results are being displayed that does not even have the word in

    below is the whole code I have

    Code:
    <form action="" method="post">
    <input type="text" name="search">
    <input type="submit" name="submit" value="Search">
    </form>
    
    <?php
    
    $servername = 'localhost';
    $username = '';
    $password = '';
    $dbname = '';
    
    $search_value = (isset($_POST['search']));
    
    $con=new mysqli($servername,$username,$password,$dbname);
    
    if($con->connect_error){
        echo 'Connection Failed: '.$con->connect_error;
    	
        }else{
            $sql="select id, software_title, customers_email, DATE_FORMAT(date_purchased, '%d/%m/%Y') AS date_purchased, sent from product_keys_sold where software_title LIKE '%$search_value%' ORDER BY id";
    		
            $res=$con->query($sql);
    
    		// display records in a table
    echo "<table class='records'>";
    
    // set table headers
    echo "<tr>
    <th>ID</th>
    <th>Software Title</th>
    <th>Customers Email</th>
    <th>Date Purchased</th>
    <th>Sent</th>
    <th colspan='2'>Actions</th>
    </tr>";
    
            while($row=$res->fetch_assoc()){
    			echo "<tr>";
    echo "<td><a href='view-specific-product-key-sold.php?id=" . $row['id'] . "'>".$row['id'] . "</a></td>";
    echo '<td>' . $row["software_title"]; '</td>';
    echo '<td>' . $row["customers_email"]; '</td>';
    echo '<td>' . $row["date_purchased"]; '</td>';
    echo '<td>' . $row["sent"]; '</td>';
    echo "<td><a href='add-update-keys-sold.php?id=" . $row['id'] . "'>Edit</a></td>";
    echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
    echo "</tr>";
    		}
    		
    		echo '</table>';
    
                }       
            
    ?>
    for example I type windows in the search input field and the database records that get returned does not even have the word windows in?

    UPDATE:
    I think it is to do with the following line cause even if I click search, the last record disappears and only shows the first two records in the db table

    Code:
    $search_value = (isset($_POST['search']));

Similar Threads

  1. Mysqli vs Mysql and CMS
    By Victro in forum MySQL and other databases
    Replies: 2
    Last Post: 06-16-2010, 01:14 PM
  2. Storing Checkbox Data
    By resilient in forum MySQL and other databases
    Replies: 1
    Last Post: 02-15-2009, 05:35 PM
  3. Checkbox Data converted to plain text
    By pranceatron in forum JavaScript
    Replies: 0
    Last Post: 04-14-2008, 05:03 PM
  4. Replies: 1
    Last Post: 10-27-2007, 01:04 PM
  5. Checkbox array to delete mysql data
    By jnscollier in forum PHP
    Replies: 5
    Last Post: 05-26-2007, 02:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •