PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hello! guys ,i'm new in php and using a SAMS "php and MySql web development" ebook and i'm on the stage in which we retreive info from the database through html search page which is below:
[syntax="html"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Book-o-Rama Catalogue search</title>
</head>
<body>
<h1>Book-o-Rama Catalogue search</h1>
<form action="result.php" method="post">
Choose search Type:<br />
<select name="searchtype">
<option value="author">Author
<option value="title">Title
<option value="isbn">ISBN
</select>
<br />
Enter search Term:<br />
<input name="searchterm" type="text" />
<br />
<input type="submit" value="search" />
</form>
</body>
</html>
and the php script that is called on submit is result.php that is bellow:[/syntax]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Book-o-Rama search results</title>
</head>
<body>
<h1>Book-o-Rama search results</h1>
<?php
$searchtype = $_POST["searchtype"];
$searchterm = $_POST["searchterm"];
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "you have not entered searchdetails.Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
$db = mysql_pconnect("localhost","root","mamamia");
if (! $db)
{
echo "Error: could not connect to the Database.Please try again later.";
exit;
}
mysql_select_db("books");
$query = "select*from books where".$searchtype."like'%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p> Number of books found: ".$num_results."</p>";
for($i = 0; $i<$num_results ;$i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).".Title : ";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</strong><br>Author : ";
echo htmlspecialchars(stripslashes($row["author"]));
echo "<br>ISBN: ";
echo htmlspecialchars(stripslashes($row["isbn"]));
echo "<br>Price : ";
echo htmlspecialchars(stripslashes($row["price"]));
echo "</p>" ;
}
?>
</body>
</html>
I'm using dreamweaver 8 with xampp v1.5.5 and the fact is that the php code is having a error that i can't find 2 weeks now.I don't anderstand.every thing is working apart from this one.
I need serious help.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks i'll try it.What ebook do you think i should use for learning php the good way and where to find it?
One thing i like in this forums is that there is alays somebody to answer.i really like it.thanks a lot
Honestly, I would search these forums for 'tutorials' or 'php books'. There are a lot of them out there. And all should be teaching better than what you are learning from.
$query = "select * from books where '$searchtype' like '$searchterm' ";
from the search page it is not considering the $searchtype and $searchterm and it is showing every thing on the database table "books".don't know what is going on
could not query the database:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''like' Michael Morgan' at line 1
could not query the database:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near like at line 1
could not query the database:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''like' Michael Morgan' at line 1
because $searchterm store "Michael Morgan" from the search page and $searchtype stor the name of a column in my database's books table.It's seems like $searchtype variabl e srting is empty.I added this