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条)

报告相同问题?

悬赏问题

  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要