简体   繁体   中英

How to parse the information from mysql database to html page using php

I have created one HTML page which takes input from user and I need to fetch particular row's information.

Below is the HTML code saved in "ProcessDetails.html"

<form action="details.php" method="get"/>
<h3 align="center"><FONT color=#CCFF66>ENTER SAMPLE NAME</h3>
<p align="center"> 

<input type="text" id="Samplename" name="Sample_name"/>

</p>
<div style="text-align:center"> 
<button     type="submit" value="SEARCH">
   <img alt="ok" src=
   "http://www.blueprintcss.org/blueprint/plugins/buttons/icons/tick.png" /> 
   SEARCH
  </button>
</form>  

Below is the php script saved as "details.php"

<?php
$userinput = $_GET['Sample_name'];
  $servername = "localhost";
$username = "root";
$password = "";
$dbname = "ProcessTrackingSystem";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}

$result = mysqli_query($conn, "SELECT * FROM ProcessDetails WHERE Sample_name = '$userinput'") or die(mysqli_error($conn));

$row = mysqli_fetch_assoc($result);



while ($row=mysqli_fetch_row($result))
{
printf ("%s (%s)\n",$row[0],$row[1]);
}



#printf ("SO_Number: %s \n",$row["SO_Number"])
#print_r($row);

printf ("SO_ID:->");
printf ($row['SO_ID']);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("No of samples:->");
printf ($row['No_of_samples']);
printf ("<br>\r\n");
printf ("<br>\r\n"); 

printf ("Sample name:->");
printf ($row['Sample_name']);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Client name:->");
printf ($row["Clientname"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Institution:->");
printf ($row["Institution"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Run number:->");
printf ($row["Runnumber"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Obtained reads:->");
printf ($row["Obtainedreads"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Rerun Info:->");
printf ($row["RerunInfo"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Total reads:->");
printf ($row["Totalreads"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Run date:->");
printf ($row["Rundate"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Raw data location:->");
printf ($row["Rawdatalocation"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Analyst:->");
printf ($row["Analyst"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Mentor:->");
printf ($row["Mentor"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Analysis start date:->");
printf ($row["Analysisstartdate"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Analysis end date->:");
printf ($row["Analysisenddate"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Report location->:");
printf ($row["Reportlocation"]);



mysqli_free_result($result);
$conn->close();
?>  

I need all these data in table format based in Sample name row. Now it's not displaying any output in new web page.

Help me out to do so, thanks in advance.

删除此行

$row = mysqli_fetch_assoc($result);

In your form try to use post method to post the value to other page

<form action="details.php" id="searchForm" method="post">

Try to use request method instead of get method like

$userinput = $_REQUEST['Sample_name'];

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