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> Quote Link to comment 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(); } Quote Link to comment 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(); } } Quote Link to comment 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 />"); } } ?> Quote Link to comment 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? Quote Link to comment 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 ? Quote Link to comment 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'); ?> Quote Link to comment 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 Quote Link to comment 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 />"); } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 Remove... $search=$_POST["search"]; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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... Quote Link to comment 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.