Sinisterly
Database Search Script Help - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: PHP (https://sinister.li/Forum-PHP)
+--- Thread: Database Search Script Help (/Thread-Database-Search-Script-Help)



Database Search Script Help - Oni - 08-30-2014

Code:
<?php global $headerinclude, $header, $theme, $footer, $templates, $lang, $user; //Capture search and remove pointless spaces... $searchTerm1 = trim($_GET['keyname1']); $searchTerm2 = trim($_GET['keyname2']); //Make sure that they are searching, and for only one thing... if (empty($searchTerm1) && empty($searchTerm2)) { $information = "Enter the username or email you are searching for."; } elseif (!empty($searchTerm1) && !empty($searchTerm2)) { $information = "You entered both a username and email. You may only search for one at a time."; } else { //Database information... $host = "[snip]"; //server $db = "[snip]"; //database name $user = "[snip]"; //database user name $pwd = "[snip]"; //password //Connect to server and create link to database... $link = mysqli_connect($host, $user, $pwd, $db); //Define query, based on which searchTerm isn't empty... if ((!empty($searchTerm1)) && (empty($searchTerm2))) { $query = "SELECT * FROM mybb_users WHERE username LIKE '%$searchTerm1%'"; } elseif (empty($searchTerm1) && !empty($searchTerm2)) { $query = "SELECT * FROM mybb_users WHERE email LIKE '%$searchTerm2%'"; } $results = mysqli_query($link, $query); // Check for matching results... if(mysqli_num_rows($results) >= 1) { $output = ""; while($row = mysqli_fetch_array($results)) { $output .= "<p>" . "Username: " . $row['username'] . "<br />"; $output .= "Email: " . $row['email'] . "<br />"; $output .= "Password: " . $row['password'] . "<br />"; $output .= "Salt: " . $row['salt'] . "<br />"; $output .= "Last Used: " . gmdate("m-d-y", $row['lastvisit']) . "<br />"; $output .= "Description: " . $row['origin'] . "</p>"; } echo $output; } else { $information = "There were no matching entries for the username or email you provided."; } } $template = '<html> <head> <title>' . $pages['name'] . '</title> {$headerinclude} </head> <body> {$header} {$errors} <table class="tborder" border="0" cellspacing="0" cellpadding="5"> <tr> <td class="thead" width="100%" colspan="2"><strong>Upgrade</strong></td> </tr> <tr> <td class="trow1"> $information </td> </tr> </table> {$footer} </body> </html>'; $template = str_replace("\'", "'", addslashes($template)); add_breadcrumb($pages['name']); eval("\$page = \"" . $template . "\";"); output_page($page); ?>

Was making a page within Page Manager to allow people to search a database (not Sinisterly's!). Was curious if there was a way to display $output as $information, rather than echo it.


RE: Database Search Script Help - Reiko - 08-30-2014

PHP Code:
$information = $output; // Twenty five character limit. There wasn't much else to be said.



RE: Database Search Script Help - Lain - 08-30-2014

(08-30-2014, 12:37 PM)Reiko Wrote:
PHP Code:
$information = $output; // Twenty five character limit. There wasn't much else to be said.

Code:
[8/30/14, 1:25:24 PM] Poochyena: Um $information = $output? [8/30/14, 1:25:35 PM] Poochyena: (I TL;DR’d it) [8/30/14, 4:19:44 PM] Oni | SL: I tried that. [8/30/14, 4:19:47 PM] Oni | SL: Doesn't work.



RE: Database Search Script Help - Shebang - 08-30-2014

http://hastebin.com/iganivogus.php .. maybe? I don't know, I'm tired.


RE: Database Search Script Help - Oni - 08-31-2014

(08-30-2014, 12:37 PM)Reiko Wrote:
PHP Code:
$information = $output; // Twenty five character limit. There wasn't much else to be said.

Nono, I tried that. That's what's weird. It doesn't work.


RE: Database Search Script Help - Shebang - 08-31-2014

(08-31-2014, 04:45 AM)Oni Wrote: Nono, I tried that. That's what's weird. It doesn't work.

Uh, have you tried forcing an error? Like, cause the if-else to trigger in one of the other brackets. Does the $information variable still display?


RE: Database Search Script Help - Oni - 08-31-2014

(08-30-2014, 02:44 PM).Shebang Wrote: http://hastebin.com/iganivogus.php .. maybe? I don't know, I'm tired.

Tried that as well, didn't work either.


RE: Database Search Script Help - Oni - 09-02-2014

Still no solution. I am inclined to think it is an issue with the plugin we use to deliver custom pages.


RE: Database Search Script Help - Shebang - 09-02-2014

Ignoring the spam, I noticed $information isn't instantiated outside of the if block. So the template won't be able to add $information if it doesn't exist. I don't know much about PHP, but that seems to be what the issue is.