Connection to database error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
peachiness
Forum Commoner
Posts: 41
Joined: Mon Oct 11, 2010 1:33 pm

Connection to database error

Post by peachiness »

For some reason, the search is not pulling records from my database.

I know I am searching for results that are present, but keep showing 'No results found.'

Code: Select all

<?php

//get data

$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button) 
	echo "You didn't submit a keyword.";
else
{
if (strlen($search)<=2)
echo "search term too short.";
else
{
echo "You searched for $search <hr size='1'>";


//connect to database and search

mysql_connect("localhost", "root", "");

mysql_select_db ("a2288820_data");



//explode our search term

$search_exploded = explode("", $search);

// doughhhhh

foreach($search_exploded as $search_each)

//construct query

$x++;
if ($x==1)
$construct .="keyword1 LIKE '%$search_each%'";
else
$construct .="OR keyword1 LIKE '%$search_each%'";


//echo out construct

$construct = "SELECT * FROM publications WHERE $construct";
$run = mysql_query($construct);

$foundnum = mysql_num_rows($run);

if ($foundnum==0)
echo "No results found.";
else
{
echo "$foundnum results found!<p>";

while ($runrows = mysql_fetch_assoc())
{

//get data

$author = $runrows['author1'];

echo "
<b> $author</b>
";


}

}


}
}

?>
Please help!!!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Connection to database error

Post by AbraCadaver »

Code: Select all

echo $construct;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
peachiness
Forum Commoner
Posts: 41
Joined: Mon Oct 11, 2010 1:33 pm

Re: Connection to database error

Post by peachiness »

AbraCadaver wrote:

Code: Select all

echo $construct;
What do you mean by that?
Post Reply