JAVA N WEB TECH SYLLABUS

Thursday, November 17, 2011

Program to search a book for a title given by the user on a web page and display the search results with proper headings.


book.html
<html>
    <body>
    Enter the Book isbn to search
    <br>
    <form action="http://192.168.8.3/naveen/book.php" method="get">
    ISBN:<input type="text" name="bisbn">
       <input type="submit" >
    <input type="reset">
    </form>
    </body>
    </html>




book.php


<?
                $isbn=$_GET["bisbn"];
                $query1="Select * from book where ano like '$isbn'";
                echo "$query1";
                
                
                // connect to the mysql server on localhost 
                $mysql = mysql_connect("localhost", "naveen", "a") 
                    or die("could not connect to mysql"); 

                    
                // execute the MySQL query, grab the result in $result 
                $result = mysql_db_query("naveen", $query1) 
                    or die("query failed  ");
                    

            ?> 
            <html> 
            <head> 
            <title>PHP and MySQL</title> 
            </head> 
            <body bgcolor="CYAN"> 
            <H1>THE SEARCH RESULT IS DISPLAYED BELOW</H1><BR> 
            <hr> 
            We found <b> <?echo mysql_num_rows($result); ?></b> rows. 

            <h3>Query result</h3> 
            <br>
            <table border=2>
            <tr>
                
                <td>ISBN</td>
                <td>TITLE</td>
<td>AUTHOR</td>
                <td>EDITION</td>
<td>PUBLICATION</td>



                
            </tr>

                
             <?
                //loop through each row 
                while ($array = mysql_fetch_row($result)) 
                { 
                    echo "<tr>";

                    echo "<td>$array[0]</td>";
                    echo "<td>$array[1]</td>";
echo "<td>$array[0]</td>";
                    echo "<td>$array[1]</td>";
  echo "<td>$array[1]</td>";



                    
                echo "</tr>";
             
                } 
            ?> 
            </table>
            </body> 
            </html> 
             <?
                // we are all done, so close the MySQL connection 
                mysql_close($mysql); 
            ?> 

No comments:

Post a Comment