jamesxg1 Posted January 28, 2009 Share Posted January 28, 2009 Iv made this script but it doesnt show any at all results heres the code <?php session_start(); require("../db/db.php"); //include database file require("../db/config.php"); //include configuration file require("../db/util.php"); isloggedin(); accessneeded("C"); ?> <? $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM users WHERE username, lastname, firstname, email LIKE '%$search%'"); //grab all the content while($row=@mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $lastname=$row["lastname"]; $firstname=$row["firstname"]; $username=$row["username"]; $email=$row["email"]; //display the row echo "$firstname <br> $lastname <br> $username <br> $email"; } ?> This is the form for it <form method="post" action="search.php"> <input type="text" name="search" size=25 maxlength=25> <input type="Submit" name="Submit" value="Submit"> </form> Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/ Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 You never actually check for any results. if ($result = mysql_query("SELECT * FROM users WHERE username, lastname, firstname, email LIKE '%$search%'")) { if (mysql_num_rows($result)) { //grab all the content while($row=@mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $lastname=$row["lastname"]; $firstname=$row["firstname"]; $username=$row["username"]; $email=$row["email"]; //display the row echo "$firstname <br> $lastname <br> $username <br> $email"; } } else { echo "No results found"; } } else { echo "Query failed<br />" mysql_error(); } Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-748959 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Never even noticed it before but your query is all sorts of messed up. Try... if (isset($_POST['Submit'])) { $search = mysql_real_escape_string($_POST["search"]); $sql = "SELECT firstname, lastname, username, email FROM users WHERE username LIKE '%$search%' || lastname LIKE '%$search%' || firstname LIKE '%$search%' || email LIKE '%$search%'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { //grab all the content while($row=@mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $lastname=$row["lastname"]; $firstname=$row["firstname"]; $username=$row["username"]; $email=$row["email"]; //display the row echo "$firstname <br> $lastname <br> $username <br> $email"; } } else { echo "No results found"; } } else { echo "Query failed<br />" mysql_error(); } } Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-748965 Share on other sites More sharing options...
jamesxg1 Posted January 28, 2009 Author Share Posted January 28, 2009 You never actually check for any results. if ($result = mysql_query("SELECT * FROM users WHERE username, lastname, firstname, email LIKE '%$search%'")) { if (mysql_num_rows($result)) { //grab all the content while($row=@mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $lastname=$row["lastname"]; $firstname=$row["firstname"]; $username=$row["username"]; $email=$row["email"]; //display the row echo "$firstname <br> $lastname <br> $username <br> $email"; } } else { echo "No results found"; } } else { echo "Query failed<br />" mysql_error(); } Ok with this code it still have no results. <?php session_start(); require("../db/db.php"); //include database file require("../db/config.php"); //include configuration file require("../db/util.php"); isloggedin(); accessneeded("C"); ?> <? $search=$_POST["search"]; if (isset($_POST['Submit'])) { $search = mysql_real_escape_string($_POST["search"]); $sql = "SELECT firstname, lastname, username, email FROM users WHERE username LIKE '%$search%' || lastname LIKE '%$search%' || firstname LIKE '%$search%' || email LIKE '%$search%'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { //grab all the content while($row=@mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $lastname=$row["lastname"]; $firstname=$row["firstname"]; $username=$row["username"]; $email=$row["email"]; //display the row echo "$firstname <br> $lastname <br> $username <br> $email"; } } else { echo "No results found"; } } else { echo ("Query failed<br />"); } } ?> Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-748975 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Use <?php not <? and what message is being displayed if any? Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-748985 Share on other sites More sharing options...
jamesxg1 Posted January 28, 2009 Author Share Posted January 28, 2009 Use <?php not <? and what message is being displayed if any? Hiya, Iv used <?php and still nothing.... i just get a empy screen :S, Could it be something to do with my db.php file seeing as this is my Database connection script and i do have ott security on it ? Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-748992 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Put this at the top of your script. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-748995 Share on other sites More sharing options...
jamesxg1 Posted January 28, 2009 Author Share Posted January 28, 2009 Put this at the top of your script. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> i now get Notice: Undefined index: search in D:\xampp\htdocs\main\search.php on line 17 Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749004 Share on other sites More sharing options...
jamesxg1 Posted January 28, 2009 Author Share Posted January 28, 2009 Put this at the top of your script. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> i now get Notice: Undefined index: search in D:\xampp\htdocs\main\search.php on line 17 ok now i have put single quotes on the 17th lines i get a error on line 13 <?php session_start(); require("../db/db.php"); //include database file require("../db/config.php"); //include configuration file require("../db/util.php"); isloggedin(); accessneeded("C"); ?> <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> <?php $search=$_POST["search"]; if (isset($_POST['Submit'])) { $search = mysql_real_escape_string($_POST["search"]); $sql = 'SELECT firstname, lastname, username, email FROM users WHERE username LIKE '%$search%' || lastname LIKE '%$search%' || firstname LIKE '%$search%' || email LIKE '%$search%''; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { //grab all the content while($row=@mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $lastname=$row["lastname"]; $firstname=$row["firstname"]; $username=$row["username"]; $email=$row["email"]; //display the row echo "$firstname <br> $lastname <br> $username <br> $email"; } } else { echo "No results found"; } } else { echo ("Query failed<br />"); } } ?> Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749006 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Remove... $search=$_POST["search"]; Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749019 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Also, the query needs to be in double quotes. Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749020 Share on other sites More sharing options...
jamesxg1 Posted January 28, 2009 Author Share Posted January 28, 2009 Also, the query needs to be in double quotes. ok removed, and double quotes empty screen what could this be :s ?, im very stumped :s Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749034 Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 This meens your form isn't submitting properly. Is that your exact form and is this script called search.php? Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749057 Share on other sites More sharing options...
jamesxg1 Posted January 29, 2009 Author Share Posted January 29, 2009 This meens your form isn't submitting properly. Is that your exact form and is this script called search.php? yes every script i have posted on this thread is exact to what i have in my dir... Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749088 Share on other sites More sharing options...
jamesxg1 Posted January 29, 2009 Author Share Posted January 29, 2009 This meens your form isn't submitting properly. Is that your exact form and is this script called search.php? Anyone any ideas to why it isnt working? yes every script i have posted on this thread is exact to what i have in my dir... Link to comment https://forums.phpfreaks.com/topic/142866-mysql-search-not-working/#findComment-749125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.