Hi

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)

<?php

//connect to mysql

mysql_connect("localhost","root",""); 
	
//select which database you want to edit
mysql_select_db("rewards"); 

$search=$_POST["search"];

//get the mysql and store them in $result

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

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
  
   $ID1=$r["ID1"];  
   $Firstname=$r["Firstname"];
   $Surname=$r["Surname"];
   $Cellphone=$r["Cellphone"];
   $ID_number=$r["ID_number"];
   $SalesCode=$r["SalesCode"];
   $ShopID=$r["ShopID"];
   
 //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

Interesting.

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

- Mitko Kostov

Hi

Thanks for the reply

Do you meen

print $result;

Hi.

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."%'");

Hey,

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">
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<?php echo $data; ?>
</body>
</html>

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, networking, learning, and sharing knowledge.