This is my first post here and I have just started using php so please be kind LOL

I have tried to use the script below to do a search on the database
but it keeps spitting out (Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\web\1\search.php on line 23)


//connect to mysql

//select which database you want to edit


//get the mysql and store them in $result

$result = mysql_query("SELECT * FROM contacts WHERE message LIKE '%$search%'");

//grab all the content
   //the format is $variable = $r["nameofmysqlcolumn"];
 //display the row
   echo "$ID1 <br> $Firstname <br> $Surname <br> $Cellphone <br> $ID_number | $SalesCode <br> $ShopID <br>";


I would really appreciate your help

Thanking you in advance

Recommended Answers

All 8 Replies


Please, print the sql query and try to execute it in PHPMyAdmin ( if you have ).

- Mitko Kostov


Thanks for the reply

Do you meen

print $result;


It seems that the query is the problem.

$query = "SELECT * FROM contacts WHERE message LIKE '%$search%'";

 echo $query;

- Mitko Kostov

try this one;

$result = mysql_query("SELECT * FROM topics WHERE Title LIKE '%".$search."%'");


You need to include the connection as a paramater within the mysql_query method. For example,

$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

$q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
        $result = mysql_query($q, $connection);

Now just apply what i described above to your situation.

Hope it helped!

Hi bud thanks for the reply I just retyped the code and it worked weird ????

Maybe you could help me with changing background colours and stuff when the file is a .php file

how would I make changes in php code?
or I have found sites with css help but they are all for html how do i use it with php>?

Well php isnt really made for presentation. The standard is to make any style/presentation effects through css. I don't even think you can change the background w/ php, I could be wrong though.

You can put PHP code everywhere in your XHTML page with php extension ( except some functions like header ... ). For example :

<!DOCTYPE Doctype goes here>
<html xmlns="http://www.w3.org/1999/xhtml">
<title><?php echo $title; ?></title>
<?php echo $data; ?>

So you can format the page using CSS ...

- Mitko Kostov

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.