yozza84 Posted April 13, 2008 Share Posted April 13, 2008 Hi All, Can someone please help me i have been searching all over the internet for ages now and still no one can help me even though it is simple. <?php include("header.php"); echo "<body>"; include("navbar.php"); include("bleftnav.php"); /*include("project1.php");*/ include ("searchbar.php"); //stuff goes here //wildcard $stext = $_POST['text']; $username="######"; $password="######"; $db_name="######"; $tbl_name="######"; $column="Name1"; mysql_connect("localhost", $username, $password)or die("cannot connect server "); mysql_select_db("yojodb")or die("cannot select DB"); /*$query = sprintf("SELECT Name1, Phone FROM main WHERE Name1 LIKE $stext", mysql_real_escape_string($stext), mysql_real_escape_string($Phone));*/ $result = mysql_query("SELECT $column FROM $tbl_name WHERE $column LIKE $stext"); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } while ($row = mysql_fetch_assoc($result)) { echo "<div class='results'><p>Name :   {$row['Name']} </p></div> " ; echo "<div class='results'><p>Phone :   {$row['Phone']} </p></div> " ; } if (isset($result)) { echo "<div class='results'><p>Here are the Results, If your results do not appear you may need to refine your search.</p></div>"; } echo $query; mysql_free_result($result); mysql_close()or die("cannot close connection"); include("footer.php"); ?> When we try to use the 'wildcard' we type in 's' for example and comes up with an error Error: "Invalid query: Unknown column 's' in 'where clause' Whole query:" if anyone can help it will be much appreciated!! been trying to figure it out for ages like whats wrong with me code, i tried loads of methods to use the wildcard i am willing to try anything so any suggestions welcome Smiley Quote Link to comment https://forums.phpfreaks.com/topic/100902-solved-hellllllp-simple-query-problem-mysql/ Share on other sites More sharing options...
mwasif Posted April 13, 2008 Share Posted April 13, 2008 Do you have any column named s? Quote Link to comment https://forums.phpfreaks.com/topic/100902-solved-hellllllp-simple-query-problem-mysql/#findComment-516010 Share on other sites More sharing options...
Barand Posted April 13, 2008 Share Posted April 13, 2008 Please use code tags round your code String values need to be in quotes <?php $result = mysql_query("SELECT $column FROM $tbl_name WHERE $column LIKE '$stext%' "); Quote Link to comment https://forums.phpfreaks.com/topic/100902-solved-hellllllp-simple-query-problem-mysql/#findComment-516014 Share on other sites More sharing options...
yozza84 Posted April 13, 2008 Author Share Posted April 13, 2008 maybe i didnt explain it that well. Please read the sql query i am using and see where the variable is, then see the error im getting. SELECT Name1, Phone FROM main WHERE Name1 LIKE $stext //This is the query This is the error, i had this error when i typed 's' into the search bar on my website. As you can see the $stext is not meant to be the column, rather the string (or woteva) Error: "Invalid query: Unknown column 's' in 'where clause' Whole query:" does anyone see what i mean? We've been having this problem for days now Any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/100902-solved-hellllllp-simple-query-problem-mysql/#findComment-516140 Share on other sites More sharing options...
Barand Posted April 13, 2008 Share Posted April 13, 2008 I gave you the solution. Put the $stext variable in quotes. If you don't, the query reads like SELECT Name1, Phone FROM main WHERE Name1 LIKE s Because there are no quotes around the s SQL assumes it is a column name. PS If you aren't going to to take the advice when it's given, don't bother posting and wasting everyone's time. Quote Link to comment https://forums.phpfreaks.com/topic/100902-solved-hellllllp-simple-query-problem-mysql/#findComment-516157 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.