从html字段中选择一个sql字段并将其显示在另一个页面中

时间:2016-02-18 06:59:11

标签: php html

我在html表中显示了sql表,在所有字段附近做了一个超链接,当我点击它时,整个字段的详细信息应该显示在其他页面中(即;我只显示表中2个字段的sql并想要显示在另一页休息。)

admin.php的

  <?php
    $con= mysql_connect("localhost","root","");
    mysql_select_db("main",$con);
echo"<form action=\"post\" class=\"form-horizontal\" role=\"form\">";
echo "<table width='700' height='150' onclick='myFun(event)'>";
echo"   <tr>
        <td width='100' align='center'></td>
        <td width='100' align='center'><b><u>NAME</u></b></td>
        <td width='100' align='left'><b><u>E-MAIL</u></b></td>
    </tr>
    ";
 $result=mysql_query("select NAME,EMAIL from admin order by AID");
    while($row=mysql_fetch_array($result))
        {
    echo "<tr>";
    echo"<td width='100' align='center'><a href='viewadmin.php?name=".$row['NAME']."'>Select</a></td>";
    echo"<td width='100' align='center'>".$row['NAME']."</td>";
    echo"<td width='100' align='left'>".$row['EMAIL']."</td>";
    echo"</tr>";
        }
echo"</table>";


echo"</form> ";
 ?>  

viewadmin.php

<?php
$name = $_GET['name'];
$result=mysql_query("SELECT NAME,DOB,MOB,EMAIL, FROM admin WHERE NAME = $name");
if (false === $result) {
    echo mysql_error();
}
 else {
    $row=mysql_fetch_row($result);
}

echo" <form class=\"form-horizontal\" role=\"form\">
<table width='400'>
    <tr>
        <td  align='left'>Name</td>
        <td align='left'>".$row['NAME']."</td>
    </tr>
    <tr>
        <td align='left'>E-mail</td>
        <td align='left'>".$row['EMAIL']."</td>
    </tr>   

    <tr>
        <td align='left'>D.O.B</td>
        <td  align='left'>".$row['DOB']."</td>
    </tr>
    <tr>
        <td align='left'>Mobile</td>
        <td align='left'>".$row['MOBILE']."</td>
    </tr>
    <tr>
        <td align='left'>Photo</td>
        <td ><img src='uploads/grumpy.jpg' height='200' width='200'></td>
    </tr>
</table>";
echo"</form> ";
?>                 

3 个答案:

答案 0 :(得分:0)

做这样的事情:
admin.php的

$result=mysql_query("select NAME,EMAIL from admin order by AID");
while($row=mysql_fetch_array($result)) {
    echo "<tr>";
    echo"<td width='100' align='center'><a href='viewadmin.php?name=".$row['NAME']."'>Select</a></td>";
    echo"<td width='100' align='center'>".$row['NAME']."</td>";
    echo"<td width='100' align='left'>".$row['EMAIL']."</td>";
    echo"</tr>";
}
echo"</table>";

并在viewadmin.php中

$name = $_GET['name'];
$result=mysql_query("SELECT * FROM admin WHERE name = $name");
$row=mysql_fetch_row($result);
echo "  <form class=\"form-horizontal\" role=\"form\">
        <table width='400'>
        <tr>
            <td  align='left'>".$row['NAME']."</td>
            <td align='left'></td>
        </tr>
        <tr>
            <td align='left'>".$row['EMAIL']."</td>
            <td align='left'>...";

答案 1 :(得分:0)

首先通过php页面重命名html页面,然后你可以在GET的帮助下将主键或行的任何键从第一页传递到管理页面。 例如: first.php      <?php $result=mysql_query("select ID,NAME,EMAIL from admin order by AID"); while($row=mysql_fetch_array($result)){ ?><a hre='admin.php?id="$id=<?php $row[0] ?>"'></a> <?php } ?>

并在admin.php页面中 你可以访问像

这样的值
echo $_GET['id'];

答案 2 :(得分:0)

停止使用MySQL并使用MySQLi,此代码应该可以正常工作

<?php
$db_connect = mysqli_connect('localhost', 'root', 'pass', 'database');
if (mysqli_connect_errno($db_connect)) {
    die('Some error occurred during connection to the database');
}
$name = mysqli_real_escape_string($db_connect,$_REQUEST['name']);
if($stmt = mysqli_prepare($db_connect, 'SELECT * FROM admin WHERE name = ?')){
    mysqli_stmt_bind_param($stmt, 's', $name);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    if(mysqli_num_rows($result) !== 0){ 
        $row = mysqli_fetch_assoc($result);
        echo "<form class=\"form-horizontal\" role=\"form\">
        <table width='400'>
        <tr>
            <td  align='left'>".$row['NAME']."</td>
            <td align='left'></td>
        </tr>
        <tr>
            <td align='left'>".$row['EMAIL']."</td>
            <td align='left'>..."
    }
    else{
        echo 'not found';
    }
}
else{
trigger_error('error:' . mysqli_errno($db_connect) . mysqli_error($db_connect));
    }
?>