Using PHP and MySQL develop a program to accept book information and search for specific book

By | October 31, 2011

Using PHP and MySQL develop a program to accept book information viz. Accession number, Title, Authors, Edition and Publisher form a web page and store the information in a database and to search for a book with the title specified by the user and to display a search results with proper headings.

prog.html

<html>
<body bgcolor="aabbcc">
<h3>
Program to accept the Book-Information </h3>
<form action="http://localhost/14.php" method="get">
<table border="0">
<tr>
<td> Enter ISBN :</td>
<td> <input type="text" name="isbn"> </td>
</tr>
<tr>
<td> Enter Title :</td>
<td> <input type="text" name="title"> </td>
</tr>
<tr>
<td> Enter Author :</td>
<td> <input type="text" name="author"> </td>
</tr>
<tr>
<td> Enter Edition :</td>
<td> <input type="text" name="edition"> </td>
</tr>

<tr>
<td> Enter Publication :</td>
<td> <input type="text" name="publication"> </td>
</tr>
<tr>

<td> <input type="submit" value="submit"> 
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>

Output:


 

 

prog.php

<?

$isbn=$_REQUEST[“isbn”];

$title=$_REQUEST[“title”];

$author=$_REQUEST[“author”];

$edition=$_REQUEST[“edition”];

$publication=$_REQUEST[“publication”];

 

$mysql=mysql_connect(“localhost”,”root”) or die(“cannot connect”);

mysql_select_db(“books”) or die(“cannot select”);

mysql_query(“insert into book_info values(‘$isbn’,’$title’,’$author’,’$edition’,’$publication’)”) or die (“query failed to insert”);

$result=mysql_query(“select * from book_info”);

?>

 

<html>

<head> <title> PHP and MYSQL </title> </head>

<body bgcolor=”aabbcc”>

<a href=”14b.html”> To search click here </a>

<table border=”1″>

<tr>

<th> ISBN </th>

<th> TITLE </th>

<th> AUTHOR </th>

<th> EDITION </th>

<th> PUBLICAITON </th>

 

</tr>

<?while($array=mysql_fetch_row($result)):?>

<tr>

<td><?echo $array[0];?> </td>

<td><?echo $array[1];?> </td>

<td><?echo $array[2];?> </td>

<td><?echo $array[3];?> </td>

<td><?echo $array[4];?> </td>

</tr>

<?endwhile;?>

<?mysql_free_result($result);?>

<?mysql_close($mysql);?>

</table>

</body>

</html>

 

Output:


Program for searching :

search.html

<html>

<body bgcolor=”aabbcc”>

<h3> Search Page </h3>

<form action = “http://localhost/search.php” method=”get”>

Enter the title of the book to be searched :

<input type=”text” name=”search”>

<br>

<input type=”submit” value=”submit”>

<input type=”reset” value=”Reset”>

<br>

</form>

</body>

</html>

search.php

 

<?

$search = $_REQUEST[“search”];

$mysql = mysql_connect(“localhost”,”root”) or die(“cannot connect”);

mysql_select_db(“books”) or die (“cannot select the database”);

$result=mysql_query(“select * from book_info where title like ‘%$search%'”) or die (“cannot execute”);

?>

<html>

<body bgcolor=”aabbcc”>

<? if(mysql_num_rows($result)>0): ?>

<table border=”1″>

<tr>

<th> ISBN </th>

<th> Title </th>

<th> Author </th>

<th> Edition </th>

<th> Publication </th>

</tr>

<b> Query Executed for search</b>

<? while ($array = mysql_fetch_row($result)):?>

<tr>

<td><?echo $array[0];?> </td>

<td><?echo $array[1];?> </td>

<td><?echo $array[2];?> </td>

<td><?echo $array[3];?> </td>

<td><?echo $array[4];?> </td>

</tr>

<? endwhile;?>

<?else?>

<?echo “no rows selected”;?>

<? endif;?>

</table>

</body>

</html>

Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *