SarahCollins Posted May 5, 2006 Share Posted May 5, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/9117-searching-through-a-database/ Share on other sites More sharing options...
fenway Posted May 5, 2006 Share Posted May 5, 2006 Try adding an "or mysql_error()" after the mysql_query() call to find out why your query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/9117-searching-through-a-database/#findComment-33701 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.