-Karl- Posted March 20, 2010 Share Posted March 20, 2010 I have a script to search a database and return any finds. However, I receive this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /***/dosearch.php on line 17 This is line 17: $query = "SELECT * FROM `news` WHERE (`id` LIKE '%$_POST['search']%' OR `title` LIKE '%$_POST['search']%' OR `thumb` LIKE '%$_POST['search']%' OR `news` LIKE '%$_POST['search']%' OR `postedby` LIKE '%$_POST['search']%')"; I just can't find what's wrong. Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/ Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 Could you please post lines 10 - 20 please. Thanks Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029116 Share on other sites More sharing options...
-Karl- Posted March 20, 2010 Author Share Posted March 20, 2010 <?php if (isset($_GET['search'])) { echo <<<HTML <center>You searched for {$_GET['search']}</center> HTML; $con = mysql_connect("localhost","****","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("****", $con); // Collect guides $query = "SELECT * FROM `news` WHERE (`id` LIKE '%$_POST['search']%' OR `title` LIKE '%$_POST['search']%' OR `thumb` LIKE '%$_POST['search']%' OR `news` LIKE '%$_POST['search']%' OR `postedby` LIKE '%$_POST['search']%')"; $run = mysql_query($query); if($run){ while($arr = mysql_fetch_assoc($run)){ echo <<<HTML <font color="blue">{$arr['title']}</font><br/> <font color="white">{$arr['news']}</font><br/> <a href="#">{$arr['id']}</a><br/><br/><br/> HTML; } }else{ die("Unable to connect to database."); } } ?> There's the full code. Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029120 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 try this: <?php if (isset($_GET['search'])) { echo <<<HTML <center>You searched for {$_GET['search']}</center> HTML; $con = mysql_connect("localhost","****","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("****", $con); // Collect guides $query = "SELECT * FROM `news` WHERE (`id` LIKE $_POST['search'] OR `title` LIKE $_POST['search'] OR `thumb` LIKE $_POST['search'] OR `news` LIKE $_POST['search'] OR `postedby` LIKE $_POST['search'])"; $run = mysql_query($query); if($run){ while($arr = mysql_fetch_assoc($run)){ echo <<<HTML <font color="blue">{$arr['title']}</font><br/> <font color="white">{$arr['news']}</font><br/> <a href="#">{$arr['id']}</a><br/><br/><br/> HTML; } }else{ die("Unable to connect to database."); } } ?> Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029123 Share on other sites More sharing options...
-Karl- Posted March 20, 2010 Author Share Posted March 20, 2010 Same error Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029126 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 <?php if (isset($_GET['search'])) { echo <<<HTML <center>You searched for {$_GET['search']}</center> HTML; $con = mysql_connect("localhost","****","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("****", $con); // Collect guides $query = "SELECT * FROM `news` WHERE (`id` LIKE $_POST['search'] OR `title` LIKE $_POST['search'] OR `thumb` LIKE $_POST['search'] OR `news` LIKE $_POST['search'] OR `postedby` LIKE $_POST['search'])"; $run = mysql_query($query) or die((mysql_error()); if($run){ while($arr = mysql_fetch_assoc($run)){ echo <<<HTML <font color="blue">{$arr['title']}</font><br/> <font color="white">{$arr['news']}</font><br/> <a href="#">{$arr['id']}</a><br/><br/><br/> HTML; } }else{ die("Unable to connect to database."); } } ?> That should give another error. Give me that one Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029128 Share on other sites More sharing options...
-Karl- Posted March 20, 2010 Author Share Posted March 20, 2010 It still gave the same error. Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029130 Share on other sites More sharing options...
-Karl- Posted March 20, 2010 Author Share Posted March 20, 2010 I've managed to fix it by using {$_GET['search']} instead of $_GET['search']. Thanks anyway Now I need to figure out how to join different tables so that I can search all of them in one go Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029138 Share on other sites More sharing options...
-Karl- Posted March 20, 2010 Author Share Posted March 20, 2010 <?php if (isset($_GET['search'])) { echo <<<HTML <center>You searched for {$_GET['search']}</center> HTML; $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("****", $con); // Collect guides $query = "SELECT * FROM `news` WHERE (`id` LIKE '%{$_GET['search']}%' OR `title` LIKE '%{$_GET['search']}%' OR `thumb` LIKE '%{$_GET['search']}%' OR `news` LIKE '%{$_GET['search']}%' OR `postedby` LIKE '%{$_GET['search']}%')"; $run = mysql_query($query); if($run){ while($arr = mysql_fetch_assoc($run)){ echo <<<HTML <font color="blue">{$arr['title']}</font><br/> <font color="white">{$arr['news']}</font><br/> <a href="#">{$arr['id']}</a><br/><br/><br/> HTML; } }else{ die("Unable to connect to database."); } } ?> That's my code now, how could I change it to display a "no results found" if nothing was found from the query. And how could I join different tables and search each of the rows in there? Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029140 Share on other sites More sharing options...
-Karl- Posted March 20, 2010 Author Share Posted March 20, 2010 Done the no results part, now I'm stuck on joining the tables and searching all of the rows. Link to comment https://forums.phpfreaks.com/topic/195918-just-cant-figure-this-out/#findComment-1029151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.