Jump to content

Searching through a database


SarahCollins

Recommended Posts

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.

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

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



[b]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[/b] (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))
echo($a_row['article_title']."<BR>");
?>

<?
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// Close connection ! (please !)[!--colorc--][/span][!--/colorc--]
mysql_close($connection);
?>



any ideas?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.