Trouble with a really simple project
Posted: Tue Jun 17, 2008 12:49 pm
Hi I'm a real newbie to php and have to make a sort of dictionary for a school project. Basically what I'm trying to do is have a database of words, their definitions, and sentences, and make it searchable. So I created the database, which is called "dictionary", with the table "word". The words are under the column "wordname" the definitions under "worddef" and their sentences are under "wordsent". Since I am such a beginner I got a php for dummies book, and used example which I kind of played around with to work for my database. My problem is with "$wordname =" right about "$query". So when I just put in one of the words for this, it displays the word and definition and sentence as it should. However since I am obviously not looking to display just one word, I created an html search box. So now I tell the searchbox to run "worddisplay.php" (the name of this program) and nothing comes up when I type a word that I know is in the database. So Ive deduced that it has to be the "$wordname" function that I mentioned earlier. What do I have to make that equal so that it will display the word that is searched for in the searchbox? I know my php might not be the best for the task, but please remember that I'm a total noob...
The html form searchbox's code is:
Code: Select all
<html>
<head><title>Definitions</title></head>
<body>
<?php
$user="--------";
$host="-------";
$password="------";
$database = "dictionary";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");
$wordname = 'name'
$query = "SELECT * FROM word WHERE wordname='$wordname'";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");
/* Display results in a table */
echo "<h1>$wordname</h1>";
echo "<table cellspacing='15'>";
echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<tr>\n
<td>$worddef</td>\n
<td>$wordsent</td>\n
</tr>\n";
echo "<tr><td colspan='3'><hr /></td></tr>\n";
}
echo "</table>\n";
?>
</body></html>
The html form searchbox's code is:
Code: Select all
<head>
<title>Search</title>
</head><body>
<h3>Search Below</h3>
<form name="wordname" action="wordDisplay.php"
method="post">
Search:
<input type="text" name="name">
<input type="submit" value="Search">
</form>
</body>
</html>