Jump to content


Searching through a database

  • Please log in to reply
1 reply to this topic

#1 SarahCollins

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 May 2006 - 09:17 AM

I really cant see what i am doing wrong here, why i am getting errors thrown back at me.
Basically i have a form (form.html) which just has a search box and button.

<form action="search.php" method="post">
Search: <input type="text" name="search">
<br><br><input type="submit" value="Search">

And i wish to search through a database and show all the data in it. I just want to get this bit working before i start a specific search. i have that. when i do it individually the connecting works, selecting the database doesnt throw errors, it is the 3 and 4th bit that comes back with the following error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/stud/0/a0371212/public_html/search.php on line 18 (the address is my uni webpage)

[!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]<?
// Connect to DB server[!--colorc--][/span][!--/colorc--]
$connection = mysql_connect("clun.scit.wlv.ac.uk", "demo", "");
if (!$connection)
die("Cannot connect to DB");

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// Select database[!--colorc--][/span][!--/colorc--][/color]
mysql_select_db("alix", $connection)
or die("Cannot find DB");

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<?
// Retrieve the data[!--colorc--][/span][!--/colorc--]
$sql = "SELECT article_title FROM articles";
$result = mysql_query($sql, $connection);

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// Loop through data and display[!--colorc--][/span][!--/colorc--]
while($a_row = mysql_fetch_assoc($result))

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// Close connection ! (please !)[!--colorc--][/span][!--/colorc--]

any ideas?

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 May 2006 - 07:49 PM

Try adding an "or mysql_error()" after the mysql_query() call to find out why your query is failing.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users