Hi im trying to run a search of some data in a mysql database and im only getting as far as connecting to the database.
when i use this on the page:
@ $db = mysql_pconnect("localhost", "bookorama", "bookorama");
it won't connect to the database. When i use this
@ $db = mysql_pconnect("localhost", "Username", "password");
but changing user name and password to my real ones it connects but displays no content.
Im trying to reach to a database called bookorama and get it to search it.
I have a attached my results page, so u can see my coding maybe there is something up with it?You might find this tutorial quite handy...
<!-- m --><a class="postlink" href="http://www.spoono.com/tutorials/php/searchthanks">http://www.spoono.com/tutorials/php/searchthanks</a><!-- m --> but im still having trouble configuring the script.
im just getting a blank screen now. This is what im using
<?
//connect to server
mysql_pconnect("localhost","username","pass");
//select the db
mysql_select_db("bookorama");
//get the results and store them in $result
$result = mysql_query ("SELECT * FROM books WHERE isbn LIKE '%$search%'");
//run the while loop
while($r=mysql_fetch_array($result))
{
//grab the result
$isbn=$r["isbn"];
//print it out
echo $isbn;
echo "<br>";
}
?>
i have attached a screen shot of my database and tables, can anyone tell me how to get it to connect.
i want to access information in the bookorama database and in the books table and the isbn column.
any help would be greatful.how do you know it is not connecting? just beasue you don't get results doesn't mean it is not connecting.
//connect to server
mysql_pconnect("localhost","username","pass");
//select the db
mysql_select_db("bookorama");
//get the results and store them in $result
$result = mysql_query ("SELECT * FROM books WHERE isbn LIKE '%$search%'");
//run the while loop
if(!$result){mysql_error();}
if(mysql_num_rows($result){
while($r=mysql_fetch_array($result)){
//grab the result
$isbn=$r["isbn"];
//print it out
echo $isbn;
echo "<br>";
}
} else {
echo"No reulsts";
}
try that and see what you get. if you can't connect it will tell you "Can't Connect to database"
but if you do connect we need to know the exact error if any. try the above code and see what you getwell i didn't get the could not connect message so i think it is connecting but this error appeared
Parse error: parse error, unexpected '{' in c:\phpWeb\results.php on line 20
this is line 20
if(mysql_num_rows($result){
so i took it out then it said
Parse error: parse error, unexpected T_WHILE in c:\phpWeb\results.php on line 21
this is line 21
while($r=mysql_fetch_array($result)){
so i don't know what's up??
i have attached my search pageyou don't start taking things out just becasue ther eis apaser error. tha tmeans there i s atypo
if(mysql_num_rows($result){
should be
if(mysql_num_rows($result)){Hey scoutt i did what you said and it worked. But instead of showing what i searched for it shows all of the tables contents. I tried a script from a book i have and it's not working like it should. It should display all content relivent to my search
here is the script from the book, can you tell me if they have made a mistake or something?
<?
if (!$searchtype || !$searchterm)
{
echo"You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
//connect to server
mysql_pconnect("localhost","user","pass");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("bookorama");
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
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 stripslashes($row["Title"]);
echo "</strong><br>Author: ";
echo stripslashes($row["Author"]);
echo "</strong><br>isbn: ";
echo stripslashes($row["ISBN"]);
echo "<br>Price: ";
echo stripslashes($row["Price"]);
echo "</p>";
}
?>that is because of right here
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i <$num_results;$i++)
{
for one the first bold is wrong. do like you did above on the other post.
'%$search%'
also it depends on if you are working with register globals on or off. this is setting in the php.ini file. if OFF then you have to use the super globals to get form contents - $_POST[]
also the second bold is nowhere to be found. that varialbe is nonexistant.
do this
$num_results= mysql_num_rows($result);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i <$num_results;$i++)
{
that should work for youYou should get a PHP Info file on your server, that's what I did to get information easily and when I want it.
when i use this on the page:
@ $db = mysql_pconnect("localhost", "bookorama", "bookorama");
it won't connect to the database. When i use this
@ $db = mysql_pconnect("localhost", "Username", "password");
but changing user name and password to my real ones it connects but displays no content.
Im trying to reach to a database called bookorama and get it to search it.
I have a attached my results page, so u can see my coding maybe there is something up with it?You might find this tutorial quite handy...
<!-- m --><a class="postlink" href="http://www.spoono.com/tutorials/php/searchthanks">http://www.spoono.com/tutorials/php/searchthanks</a><!-- m --> but im still having trouble configuring the script.
im just getting a blank screen now. This is what im using
<?
//connect to server
mysql_pconnect("localhost","username","pass");
//select the db
mysql_select_db("bookorama");
//get the results and store them in $result
$result = mysql_query ("SELECT * FROM books WHERE isbn LIKE '%$search%'");
//run the while loop
while($r=mysql_fetch_array($result))
{
//grab the result
$isbn=$r["isbn"];
//print it out
echo $isbn;
echo "<br>";
}
?>
i have attached a screen shot of my database and tables, can anyone tell me how to get it to connect.
i want to access information in the bookorama database and in the books table and the isbn column.
any help would be greatful.how do you know it is not connecting? just beasue you don't get results doesn't mean it is not connecting.
//connect to server
mysql_pconnect("localhost","username","pass");
//select the db
mysql_select_db("bookorama");
//get the results and store them in $result
$result = mysql_query ("SELECT * FROM books WHERE isbn LIKE '%$search%'");
//run the while loop
if(!$result){mysql_error();}
if(mysql_num_rows($result){
while($r=mysql_fetch_array($result)){
//grab the result
$isbn=$r["isbn"];
//print it out
echo $isbn;
echo "<br>";
}
} else {
echo"No reulsts";
}
try that and see what you get. if you can't connect it will tell you "Can't Connect to database"
but if you do connect we need to know the exact error if any. try the above code and see what you getwell i didn't get the could not connect message so i think it is connecting but this error appeared
Parse error: parse error, unexpected '{' in c:\phpWeb\results.php on line 20
this is line 20
if(mysql_num_rows($result){
so i took it out then it said
Parse error: parse error, unexpected T_WHILE in c:\phpWeb\results.php on line 21
this is line 21
while($r=mysql_fetch_array($result)){
so i don't know what's up??
i have attached my search pageyou don't start taking things out just becasue ther eis apaser error. tha tmeans there i s atypo
if(mysql_num_rows($result){
should be
if(mysql_num_rows($result)){Hey scoutt i did what you said and it worked. But instead of showing what i searched for it shows all of the tables contents. I tried a script from a book i have and it's not working like it should. It should display all content relivent to my search
here is the script from the book, can you tell me if they have made a mistake or something?
<?
if (!$searchtype || !$searchterm)
{
echo"You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
//connect to server
mysql_pconnect("localhost","user","pass");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("bookorama");
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
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 stripslashes($row["Title"]);
echo "</strong><br>Author: ";
echo stripslashes($row["Author"]);
echo "</strong><br>isbn: ";
echo stripslashes($row["ISBN"]);
echo "<br>Price: ";
echo stripslashes($row["Price"]);
echo "</p>";
}
?>that is because of right here
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i <$num_results;$i++)
{
for one the first bold is wrong. do like you did above on the other post.
'%$search%'
also it depends on if you are working with register globals on or off. this is setting in the php.ini file. if OFF then you have to use the super globals to get form contents - $_POST[]
also the second bold is nowhere to be found. that varialbe is nonexistant.
do this
$num_results= mysql_num_rows($result);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i <$num_results;$i++)
{
that should work for youYou should get a PHP Info file on your server, that's what I did to get information easily and when I want it.