duanmei4149 2014-10-08 10:42
浏览 56
已采纳

从php中的sql数据库检索数据的问题

I have created register form using php. I have index.php,submit.php,functions.php and script.

Now it works fine, and i need to retrieve the data from database and display in front end.

I am new to php, and i am learning. please help me to do this.

This is my data.php:

    <?php 
    include ('condb.php');
    $query = mysql_query("select * from test where id='".$_GET['id']."'");
    $row = mysql_fetch_array($query);
?>
    <body>
        <h3>Employee Detail</h3>
        <p>Emp Name:</p> <?php echo $row['fname'];?>
        <p>LastName:</p> <?php echo $row['lname'];?>
    </body>
<?php ?>

and this is action.php:

           <?php
include('condb.php');

extract($_POST);
$que=mysql_query("INSERT INTO test (id, fname, lname) VALUES ('$id', '$fname', '$lname')") or die("Error Msg!");
if($que)
{
    header('Location: data.php?id='.$id.'');
}

?>

index.html:

<body bgcolor="#2E2E2E">
        <table align="center" cellpadding="5" style="background:#A4A4A4; border-radius:4px; margin-top:40px; padding:15px;">
            <h1 style="text-align:center; color:white; margin-top:50px">Employee Registration Form</h1>
            <form method="post" action="action.php">
                <tr><td>First Name:</td><td> <input type="text" id="fname" name="fname" required /></td></tr>
                <tr><td>Last Name:</td><td> <input type="text" id="lname" name="lname"/></td></tr>
                <tr><td></td><td><input type="submit" value="Register Me!"/></td></tr>
            </form>
        </table>
    </body>

and condb.php:

<?php 
$con=mysql_connect("localhost","root","")or die("Error!");
mysql_select_db("test") or die(mysql_error());
?>
  • 写回答

4条回答 默认 最新

  • dshqd84261 2014-10-08 10:53
    关注

    Here I have shown code for the 3 field and you can do similarly for other fields.You can make newfile and paste that code their.

    <?php
        $dbhost = 'localhost';
        $dbuser = 'root';
        $dbpass = '';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        if(! $conn )
        {
          die('Could not connect: ' . mysql_error());
        }
        $sql = 'SELECT fname, lname, email FROM crop';
    
        mysql_select_db('crop');
        $retval = mysql_query( $sql, $conn );
        if(! $retval )
        {
          die('Could not get data: ' . mysql_error());
        }
        while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
        {
            echo "First Name :{$row['fname']}  <br> ".
                 "Last Name : {$row['lname']} <br> ".
                 "Email Address : {$row['email']} <br> ".
                 "--------------------------------<br>";
        } 
        echo "Fetched data successfully
    ";
        mysql_close($conn);
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么