Jump to content

Recommended Posts

Hi

 

I am making a search form where the admin can search for a name using a input field and returns the results for records that match the name, that side of it works but I can't get the id record number retrieved from the db and make it a clickable link but I get the following error in the id column

 

Notice: Trying to get property of non-object in /home/firstqualityfina/public_html/admin/unsecured-loan-applicants/search-unsecured-loan-applicant-results.php on line 97

 

On line 97 is the following

echo "<a href='view-specific-unsecured-loan-applicant.php?id=" . $results->id ."'>".$results->id . "</a>";

The whole code looks like the following

<?php
//load database connection
    $host = "localhost";
    $user = "";
    $password = "";
    $database_name = "";
    $pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION	
    ));
// Search from MySQL database table
$search=$_POST['search'];
$query = $pdo->prepare("select id, fullname, address, emailaddress, phonenumber, mobilenumber, amountloan, term, homeowner, DATE_FORMAT(loanappdate, '%d/%m/%Y') AS 'loanappdate' from unsecured_loans where fullname LIKE '%$search%' LIMIT 0 , 10");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();

$query->execute();
// Display search result
         if (!$query->rowCount() == 0) {
			 	echo "<div style='clear: both;'>";
				echo "<br><br>";
echo "<table class='records'>";
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Full Name</th>";
echo "<th>Address</th>";
echo "<th>Email Address</th>";
echo "<th>Phone Number</th>";
echo "<th>Mobile Number</th>";
echo "<th>Unsecured Loan Amount</th>";
echo "<th>Term(Months)</th>";
echo "<th>Applicant Status</th>";
echo "<th>Unsecured Loan Application Date</th>";
echo "<th>Actions</th>";
echo "</tr>";
           echo "</thead>";
		   
		   while ($results = $query->fetch()) {
				echo "<tr><td>";
				echo "<a href='view-specific-unsecured-loan-applicant.php?id=" . $results->id ."'>".$results->id . "</a>";
				echo "</td><td>";
                echo $results['fullname'];
				echo "</td><td>";
                echo $results['address'];
				echo "</td><td>";	
                echo $results['emailaddress'];
				echo "</td><td>";	
                echo $results['phonenumber'];
				echo "</td><td>";		
                echo $results['mobilenumber'];
				echo "</td><td>";		
                echo '£' . $results['amountloan'];
				echo "</td><td>";		
                echo $results['term'];
				echo "</td><td>";
                echo $results['homeowner'];
				echo "</td><td>";
                echo date("d/m/Y", strtotime($results['loanappdate']));
				echo "</td><td>";
				echo '<a onClick=\"javascript: return confirm("Are you sure you wish to delete this applicant?");\" href="delete.php?id=<?= $row["id"]; ?>">Delete</a></td>';
				echo "</tr>";	
				echo "</table>";
				
		   }
		 }
	?>

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/303185-php-search-help/
Share on other sites

I have followed the coding from the link in your post reply but no results are showing when I do a search and what name I am searching for should return 1 result, good thing is I have no errors but not sure what I am missing

 

I have the following code now

<?php

//load database connection
    $host = "localhost";
    $user = "";
    $password = "";
    $database_name = "";
    $pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION	
    ));
$search=$_POST['search'];
$sql=$pdo->prepare("SELECT select id, fullname, address, emailaddress, phonenumber, mobilenumber, amountloan, term, homeowner, DATE_FORMAT(loanappdate, '%d/%m/%Y') AS 'loanappdate' from unsecured_loans where fullname LIKE '%$search%'");
// Search from MySQL database table
$sql->bindValue(1, "%$search%", PDO::PARAM_STR);
        
		// were any rows found?                
if ($row = $sql->fetchObject())
{
        // display records in a table
        echo "<table class='records'>";
        
        // set table headers
        echo "<tr>
        <th>ID</th>
        <th>Full Name</th>
        <th>Address</th>
		<th>Email Address</th>
        <th>Phone Number</th>
        <th>Mobile Number</th>
		<th>Unsecured Loan Amount</th>
		<th>Term(Months)</th>
		<th>Applicant Status</th>
		<th>Unsecured Loan Application Date</th>
        <th colspan='1'>Actions</th>
        </tr>";
        
       
        do {
                // set up a row for each record
                echo "<tr>";
                echo "<td>" . $row->id . "</td>";
                echo "<td>" . $row->fullname . "</td>";
                echo "<td>" . $row->address . "</td>";
                echo "<td>" . $row->emailaddress . "</td>";
				echo "<td>" . $row->phonenumber . "</td>";
				echo "<td>" . $row->mobilenumber . "</td>";
				echo "<td>" . '£' . $row->amountloan . "</td>";
				echo "<td>" . $row->term . "</td>";
				echo "<td>" . $row->homeowner . "</td>";
                echo "<td>" . $row->loanappdate . "</td>";
                echo '<td><a onClick=\"javascript: return confirm("Are you sure you wish to delete this applicant?");\" href="delete.php?id=" . $row->id . "">Delete</a></td>';
                echo "</tr>";
        }  while ($row = $sql->fetchObject());
        
        echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
        echo "No results to display!";
}

?>
Edited by ianhaney
Link to comment
https://forums.phpfreaks.com/topic/303185-php-search-help/#findComment-1542707
Share on other sites

That code that I linked you to was in a thread of yours from a few weeks ago, yet here you are again with the same problems ::)

 

Have another look at the linked code - particularly at how parameters are used in prepared queries.

Link to comment
https://forums.phpfreaks.com/topic/303185-php-search-help/#findComment-1542709
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.