在php中将mysql数据显示到文本字段的问题

时间:2016-05-30 11:14:44

标签: php mysql

好的,在这个页面上,我想做一个更新。假设页面在视图页面上单击编辑后显示/显示mysql中的数据到文本字段中。但数据似乎无法进入文本字段。这是我的parcelEdit.php代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Updating Parcel Details</title>
<link rel="stylesheet" href="css/style.css" />

</head>

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

if(isset($_POST['update']))
{   
$parcelID = $_POST['parcelID'];
$owner = $_POST['owner'];
$rcv_date = $_POST['rcv_date'];
$pck_date = $_POST['pck_date'];
$status = $_POST['status'];

// checking empty fields
if (empty($parcelID) || empty($owner) || empty($rcv_date)||
empty($pck_date)|| empty($status)) {    

    if(empty($parcelID)) {
        echo "<font color='red'>Parcel ID field is empty.</font><br/>";
    }
    if(empty($owner)) {
        echo "<font color='red'>Owner Name field is empty.</font><br/>";
    }
    if(empty($rcv_date)) {
        echo "<font color='red'>Received Date field is empty.</font><br/>";
    }
    if(empty($pck_date)) {
        echo "<font color='red'>Picked Up Date field is empty.</font><br/>";
    }
    if(empty($status)) {
        echo "<font color='red'>Parcel Status field is empty.</font><br/>";
    }   
} else {    
    //updating the table
    $result = mysql_query("UPDATE parcel SET parcelOwner = '$owner',
dateReceived = '$rcv_date', datePickup = '$pck_date', parcelStatus =
'$status' WHERE parcelID='$parcelID'");

    //redirectig to the display page. In our case, it is index.php
    header("Location: parcelView.php");
}
}
?>
<?php

//getting id from url
if(isset($_GET['parcelID'])){
$parcelID = mysql_real_escape_string($_GET['parcelID']);

//selecting data associated with this particular id
$result = mysql_query("SELECT * FROM parcel  WHERE parcelID='$parcelID'");

while($res = mysql_fetch_array($result))
{
//$mem_id= $res['mem_id'];
$parcelID= $res['parcelID'];
$owner= $res['parcelOwner'];
$rcv_date= $res['dateReceived'];
$pck_date= $res['datePickup'];
$status= $res['parcelStatus'];
}
} else {
$parcelID = '';
$owner = '';
$rcv_date = '';
$pck_date = '';
$status = '';
}

?>
<body>
    <body style='background: url(mailbox.jpg)'>
    <div align="center">
    <h1>Update Parcel Details</h1>
    <form method="post" enctype="multipart/form-data">
        <table>
        <tr>
            <Td> PARCEL ID : </td>
            <td><input name="parcelID" type="text" id="parcelID" value=<?php
echo $parcelID;?>></td>
        </tr>
        <tr>
            <Td> OWNER : </td>
            <td><input name="owner" type="text" id="owner" value=<?php echo
$owner;?>></td>
        </tr>
        <tr>
            <Td> DATE RECEIVED : </td>
            <td><input name="rcv_date" type="text" id="rcv_date" value=<?php
echo $rcv_date;?>></td>
        </tr>
        <tr>
            <Td> DATE PICKED UP : </td>
            <td><input name="pck_date" type="text" id="pck_date" value=<?php
echo $pck_date;?>></td>
        </tr>
        <tr>
            <Td> STATUS : </td>
            <td><input name="status" type="text" id="status" value=<?php
echo $status;?>></td>
        </tr>
        <tr>
            <Td colspan="2" align="center">
            <input type="submit" value="Update Records" name="update"/>
            </Td>
        </tr>
        </table>
    </form>
    </div>

</body>

</html>

这是我的parcelView.php代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>List of Parcels</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<?php
include('db.php');
include('paginate.php');
$select=mysql_query("SELECT * FROM parcel");
$i=1;
while($userrow=mysql_fetch_array($select))
{
$parcelID=$userrow['parcelID'];
$owner=$userrow['parcelOwner'];
$rcv_date=$userrow['dateReceived'];
$pck_date=$userrow['datePickup'];
$status=$userrow['parcelStatus'];
?>
<body>
<body style='background: url(homebg.jpg)'>
<div class="hdr1">
<h1>List Of Parcels</h1>
<table border="1" align="center" style="margin-top:50px;">
<tr style="background:#CCCCCC" height="30px"><th>ID</th><th>Owner</th
<th>Date Received</th><th>Date Picked Up</th>
<th>Status</th>
<th>&nbsp;</th><th>&nbsp;</th>
</tr>
</div>


<?php
$per_page = 5;  // number of results to show per page
$result = mysql_query("SELECT * FROM parcel");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);//total pages we going to
have

//-------------if page is setcheck------------------//
if (isset($_GET['page']))
{
$page = intval($_GET['page']);
$show_page = $_GET['page'];             //it will telles the current page
if ($show_page > 0 && $show_page <= $total_pages) {
    $start = ($show_page - 1) * $per_page;
    $end = $start + $per_page;
} else {
    // error - show first set of results
    $start = 0;              
    $end = $per_page;
}
} else {
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
if (isset($_GET['page'])){
$page = intval($_GET['page']);


$tpages=$total_pages;
if ($page <= 0)
$page = 1;
}
//$query=mysql_query("select * from users");
for ($i = $start; $i < $end; $i++)  
{
    if ($i == $total_results)
     {
     break;
     }

?>
<tr>
    <td><?php echo mysql_result($result, $i, 'parcelID');?></td>
    <td><?php echo mysql_result($result, $i, 'parcelOwner');?></td>
    <td><?php echo mysql_result($result, $i, 'dateReceived');?></td>
    <td><?php echo mysql_result($result, $i, 'datePickup');?></td>
    <td><?php echo mysql_result($result, $i, 'parcelStatus');?></td>
    <td><a href="parcelEdit.php?email=<?php echo mysql_result($result, $i,
'parcelID');?>">Edit</a></td>
    <td><a href="parcelDelete.php?email=<?php echo mysql_result($result, $i,
'parcelID');?>">Delete</a></td>
</tr>  

<?php }  ?>
<tr>
<td colspan="7">
 <?php 
 $tpages=$total_pages;
 $reload = "parcelView.php" . "?tpages=" . $tpages;
                echo '<div  class="pagination"><ul>';
                if ($total_pages > 1) {
                    echo paginate($reload, $show_page, $total_pages);
                }
                echo "</ul></div>";
?>
</td>
</tr>
</table>
<?php } ?>
</body>
</html>

我不知道要修复的是什么/请帮助我,因为php对我来说是新的,我仍然适应它。

1 个答案:

答案 0 :(得分:0)

要进行编辑,请创建链接:

<a href="parcelEdit.php?email=<?php echo mysql_result($result, $i,'parcelID');?>">Edit</a>

在编辑文件中,您有:

$parcelID = mysql_real_escape_string($_GET['parcelID']);

一旦设置email参数,然后搜索parcelID参数,是否真的看不到?

所以你的编辑链接应该是:

<a href="parcelEdit.php?parcelID=<?php echo mysql_result($result, $i,'parcelID');?>">Edit</a>

ps:你的视图文件很乱......你有:

<body>
<body style='background: url(homebg.jpg)'>

然后你循环生成它。你真的应该先学习一些基本的html语法。