search code
Posted by: kathierry2106 (196.44.244.---)
Date: February 21, 2008 07:53AM

hello!
i have created
a Database (library_bank)
and
Table (book). filelds.[id, author, title, publisher]

i did php form code for insert records into database
and it's working
and i managed to display records from database

Now I got problems of updating that records using a form by retrieving info of an error records and updated
my second problems is to create a search php code that will search in my database
any help it will be very kind from you

Thierry,
Best regards

Options: ReplyQuote
Re: search code
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 21, 2008 08:51AM

yes this is all simple simple stuff.




to update do it like this...

have two files. one with a form- then this form passes the information onto the database with another file
all you need to do is supply EDIT.PHP with an id number as GET or POST
is this is how you want it?


i can also show you if you want to have another page first that displays everything in the table like this

id1 auther1 title1 publisher1 edit?
id2 auther2 title2 publisher2 edit?
id3 auther3 title3 publisher3 edit?
id4 auther4 title4 publisher4 edit?
id5 auther5 title5 publisher5 edit?


and then u click edit and it shows a form
anyway below are the two files
edit.php is the form , and it send data to update_database.php which updates the table
-----------------------------------------------------------------------------
edit.php
-----------------------------------------------------------------------------------
<html>
<head>
</head>
<body>



<?php
$id=$_REQUEST['ID'];
$dbhost = 'YOURHOST';
$dbuser = 'YOURMSQLUSER';
mysql_connect($dbhost,$dbuser);
$dbname = 'library_bank';
@mysql_select_db($dbname) or die( "Unable to select database"winking smiley;
$query="SELECT * FROM book WHERE id='$id'";
$result=mysql_query($query);
mysql_close();

$id==$i;
$author=mysql_result($result,$i,"author"winking smiley;
$title=mysql_result($result,$i,"title"winking smiley;
$publisher=mysql_result($result,$i,"publisher"winking smiley;
?>

<form action="update_database.php" METHOD="POST" enctype="multipart/form-data" >


<INPUT TYPE="hidden" NAME="id" VALUE="<?php echo $id;?>">
<label>AUTHOR</label>
<INPUT TYPE="text" NAME="author" value="<?php echo$author;?>">

<label>TTTLE</label>
<INPUT TYPE="text" NAME="title" value="<?php echo$title;?>">

<label>PUBLISHER</label>
<INPUT TYPE="text" NAME="publisher" value="<?php echo$publisher;?>">


<td><INPUT class="boldit" name="submit" TYPE="submit" value="Submit"></td>
<td><INPUT class="boldit" name="reset" TYPE="reset" value="Reset"></td>



</form>
</body>
</html>






---------------------------------------------------------------------------

update_database.php
---------------------------------------------------------------------------
<?php
$dbhost = 'YOURHOST';
$dbuser = 'YOURMYSQLUSER';
mysql_connect($dbhost,$dbuser);
$dbname = 'library_bank';
@mysql_select_db($dbname) or die( "Unable to select database"winking smiley;

$id=$_POST['id'];
$author=$_POST['author'];
$title=$_POST['title'];
$publisher=$_POST['publisher'];


$query="UPDATE book SET author='$author', title='$title', publisher='$publisher' WHERE id='$id'";
mysql_query($query);
mysql_close() ;

echo 'DATABASE UPDATED';
?>

-----------------------------------------------------------------------------------------------


- JUST FILL IN UR HOST AND MYSQL USER IN BOTH FILES




explain to me what kind of search you need to be doing?



Edited 4 time(s). Last edit at 02/21/2008 09:03AM by stevenmartin99.

Options: ReplyQuote
Re: search code
Posted by: kathierry2106 (196.44.244.---)
Date: February 21, 2008 09:18AM

thank you very much
let'me running it and i wil let's u know about the result

the kind of search that I need to do
is creating a form of search wich will submit to retrieve info of records that are in Database

search form composite of where users can enter
a free, text or if they know author, or a text of the title of book they can entered into the filed and get an output of results

""""""""""""""""""""""""""""""""""
free text (or keywords)
Title
Author
""""""""""""""""""""""""""""""""""

SUBMIT BUTTON value='search' that will select correspond info of records in data base

with regards
Thierry

Options: ReplyQuote
Re: search code
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 21, 2008 09:22AM

hope u realise edit.php needs a id value sent to it so it knows which row its updating. if u dont supply it
the scripts wont run.


searchs can be simple or difficult. do u want to search for single words in the tile? if someone seaches the word "apple" any book with apple will be returned? same with author? etc

Options: ReplyQuote
Re: search code
Posted by: kathierry2106 (196.44.244.---)
Date: February 21, 2008 10:54AM

in update
i got that error
"Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in C:\wamp\www\LIBRARY\edit.php on line 21

"

yes that kind of searching
a single words in the title, or author name
or combine a signgle words of title and author

Options: ReplyQuote
Re: search code
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 21, 2008 10:57AM

did u supply a id number to the page? i just see my code has

$id=$_REQUEST['ID'];


ud need to supply ID and not id


change mine to

$id=$_REQUEST['id'];



Edited 1 time(s). Last edit at 02/21/2008 10:58AM by stevenmartin99.

Options: ReplyQuote
Re: search code
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 21, 2008 12:12PM

here is the search files


-----------------------------------------
search.php
------------------------------------------
<html>
<head>
</head>
<body>
<form action="check_database.php" METHOD="POST" enctype="multipart/form-data" >
<label>Title</label>
<INPUT TYPE="text" NAME="title"><br>
<label>Author</label>
<INPUT TYPE="text" NAME="author"><br>
<label>Publisher</label>
<INPUT TYPE="text" NAME="publisher"><br>
<br>
<td><INPUT class="boldit" name="submit" TYPE="submit" value="Submit"></td>
<td><INPUT class="boldit" name="reset" TYPE="reset" value="Reset"></td>
</form>
</body>
</html>





---------------------------------------------------------------------------------
checkdatabase.php CHANGE THE USERNAME AND HOST A TOP OF THIS
---------------------------------------------------------------------------------
<?php
MySQL_connect("localhost", "root"winking smiley;
MySQL_select_db("library_bank"winking smiley;

$title_search= $_POST['title'];
if (trim($title_search)!='')
{
$title_searchwords = explode(" ","$title_search"winking smiley;
foreach ($title_searchwords as $word)
{$title_searchstring= $title_searchstring.' +'.$word;}
$title_query=" MATCH(title) AGAINST ('$title_searchstring' IN BOOLEAN MODE)";
$join1=' && ';
}
else {$join1='';}


$author_search= $_POST['author'];
if (trim($author_search)!='')
{
$author_searchwords = explode(" ","$author_search"winking smiley;
foreach ($author_searchwords as $word)
{$author_searchstring= $author_searchstring.' +'.$word;}
$author_query=" MATCH(author) AGAINST ('$author_searchstring' IN BOOLEAN MODE)";
$join2=' && ';
}
else {$check2='1';$join2='';}


$publisher_search= $_POST['publisher'];
if (trim($publisher_search)!='')
{
$publisher_searchwords = explode(" ","$publisher_search"winking smiley;
foreach ($publisher_searchwords as $word)
{$publisher_searchstring= $publisher_searchstring.' +'.$word;}
$publisher_query=" MATCH(publisher) AGAINST ('$publisher_searchstring' IN BOOLEAN MODE)";

}
else {$join2='';
if ($check2=='1'){$join1='';}
}
$query = ("SELECT * from book where ".$title_query.$join1.$author_query.$join2.$publisher_query);
$result = MySQL_query($query);
if(!$result) {echo MySQL_error()."<br>$query<br>";}

if(MySQL_num_rows($result) > 0)
{
echo "<table border=1 >";
echo "<tr><td>Title </td><td>Author</td><td>Publisher</td></tr>";
while($row = MySQL_fetch_array($result))
{ echo "<td>{$row['title']}</td>";
echo "<td>{$row['author']}</td>";
echo "<td>{$row['publisher']}</td></tr>";
}

echo "</table>";}
else {echo "No Results were found.<br>";}
echo "<br>";
?>
<a href='search.php'>GO BACK TO SEARCHPAGE</A>



-----------------------------------------------------------------------------------------------

I know this second file may look daunting! even impossible to follow but it allows u to search as well as u want. you can search for any or all terms. you can type in the title word in any order, or authors surname in any order. ]


Your table in mysql needs to be using the ISAM engine and full text support enabled

need any help just ask



Edited 1 time(s). Last edit at 02/21/2008 12:19PM by stevenmartin99.

Options: ReplyQuote
Re: search code
Posted by: kathierry2106 (196.44.244.---)
Date: February 22, 2008 07:46AM

Good day!
that kind os search doesn't resolve my end users solution

I would like a kind of search with one field
like that:
search for:
<input type=text name='search' size=60 maxlength=255>
<input type=submit value='LIBRARY Search'> <input type='reset' value="CLEAR">

and post it by cheking in database

wich will select records from it that correspond to a string we choose.

~~~~~~~~~~~~~~~~~~~~~~
regards
Thierry

Options: ReplyQuote
Re: search code
Posted by: kathierry2106 (196.44.244.---)
Date: February 25, 2008 09:44AM

here is the error message I got when i clik on the "edit link"

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in C:\wamp\www\LIBRARY\edit.php on line 21

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in C:\wamp\www\LIBRARY\edit.php on line 22


Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in C:\wamp\www\LIBRARY\edit.php on line 23


and it won't retrieve info of record to update

in book_display.php here is the link i used
//link to update data records
echo"<td><A HREF='edit.php' STYLE='text-decoration:none' font face='Berlin Sans FB Demi'><center>CHANGE</center></A>";

~~~~~~~~~~~
best regards
Thierry

Options: ReplyQuote
Re: update and search code
Posted by: kathierry2106 (196.44.244.---)
Date: February 25, 2008 01:14PM

hey dude!
tks the update codes itis working now
I add this on edit hyperlink codes

//link tp update data recordsby pointing on id keyword

echo"<td><A HREF='edit.php?id=$get_info->id' STYLE='text-decoration:none' font face='Berlin Sans FB
Demi'><center>CHANGE</center></A>";
it working

that error was on value of retrieving info records there was no space like
<INPUT TYPE="text" NAME="author" value="<?php echo$author;?>">

i change into this one
<INPUT TYPE="text" NAME="author" value="<?php echo $author;?>">
...
thank you very much
I still working on search codes i wil let's u know the evolution

Options: ReplyQuote


Sorry, only registered users may post in this forum.