简体   繁体   中英

Get Result in Same page from Database

I am trying with PHP and MySQL Get data from database using search methods. It will show result in another page. How to get this result in same page.

This HTML Script

<html>
<head>
<title>Digital Library</title>
</head>    
<body>
<br />
<center>
<img src="logo.png"></img>
<h1>Digital Library</h1>
<h3>Enter Comapany Name</h3>
<form action="search.php" method="post">
<input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" align="center" />
</form>
</center>
</body>
</html>

This is PHP Script

<?php
mysql_connect ("localhost", "root","")  or die (mysql_error());
mysql_select_db ("vdl");

$term = $_POST['term'];

$sql = mysql_query("select * from digital_library where company_name like '%$term%'");

while ($row = mysql_fetch_array($sql)){
    Print "<strong>Comapny Name:</strong> ".$row['company_name']."<br>";
    Print "<strong> Since: </strong> ".$row['since']."<br>";
    Print "<strong> Strength: </strong> ".$row['strength']."<br>";
    Print "<strong> Head Quarters: </strong> ".$row['head_quarter']."<br>";
    Print "<strong> Location (City): </strong> ".$row['locations']."<br>";
    Print "<strong> Development Centers: </strong> ".$row['development_centers']."<br>";
    Print "<strong> Customers: </strong> ".$row['customers']."<br>";
    Print "<strong> MNC: </strong> ".$row['mnc']."<br>";
    Print "<strong> CMMI: </strong> ".$row['cmmi']."<br>";
    Print "<strong> Domains: </strong> ".$row['domains']."<br>";
    Print "<strong> Industries: </strong> ".$row['industries']."<br>";
    Print "<strong> Domain Competitors: </strong> ".$row['domain_competitor']."<br>";
    Print "<strong> Products: </strong> ".$row['products']."<br>";
    Print "<strong> Services: </strong> ".$row['services']."<br>";
    Print "<strong> Uniqueness: </strong> ".$row['uniqueness']."<br>";
    Print "<strong> URL: </strong> ".$row['url']."<br>";
    Print "<strong> Onsights: </strong> ".$row['onsight']."<br>";
    Print "<strong> Benefits: </strong> ".$row['benefits']."<br>";
    Print "<strong> Awards: </strong> ".$row['awards']."<br>";
    echo '<br/><br/>';
    }
?>

I am tried with put code into after <body> tag but it won't work.

Please see this save your html file as .php and add your php code in this file

     <?php
    $row = '';
    if(isset($_POST['term']) && !empty($_POST['term'])){
        mysql_connect ("localhost", "root","")  or die (mysql_error());
        mysql_select_db ("vdl");

        $term = $_POST['term'];

        $sql = mysql_query("select * from digital_library where company_name like '%$term%'");
$row = mysql_fetch_array($sql);
    }

        ?>
            <html>
            <head>
            <title>Digital Library</title>
            </head>    
            <body>
            <br />
            <center>
            <img src="logo.png"></img>
            <h1>Digital Library</h1>
            <h3>Enter Comapany Name</h3>
            <form action="search.php" method="post">
            <input type="text" name="term" /><br />
            <input type="submit" name="submit" value="Submit" align="center" />
            </form>
            </center>


             <?php
        if(!empty($row)){
         while ($row){
                Print "<strong>Comapny Name:</strong> ".$row['company_name']."<br>";
                Print "<strong> Since: </strong> ".$row['since']."<br>";
                Print "<strong> Strength: </strong> ".$row['strength']."<br>";
                Print "<strong> Head Quarters: </strong> ".$row['head_quarter']."<br>";
                Print "<strong> Location (City): </strong> ".$row['locations']."<br>";
                Print "<strong> Development Centers: </strong> ".$row['development_centers']."<br>";
                Print "<strong> Customers: </strong> ".$row['customers']."<br>";
                Print "<strong> MNC: </strong> ".$row['mnc']."<br>";
                Print "<strong> CMMI: </strong> ".$row['cmmi']."<br>";
                Print "<strong> Domains: </strong> ".$row['domains']."<br>";
                Print "<strong> Industries: </strong> ".$row['industries']."<br>";
                Print "<strong> Domain Competitors: </strong> ".$row['domain_competitor']."<br>";
                Print "<strong> Products: </strong> ".$row['products']."<br>";
                Print "<strong> Services: </strong> ".$row['services']."<br>";
                Print "<strong> Uniqueness: </strong> ".$row['uniqueness']."<br>";
                Print "<strong> URL: </strong> ".$row['url']."<br>";
                Print "<strong> Onsights: </strong> ".$row['onsight']."<br>";
                Print "<strong> Benefits: </strong> ".$row['benefits']."<br>";
                Print "<strong> Awards: </strong> ".$row['awards']."<br>";
                echo '<br/><br/>';
                }
        }
        ?>
            </body>
            </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM