简体   繁体   English

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

[英]Problems in displaying mysql data into text field in php

Okay so, on this page, i want to do an update. 好的,在此页面上,我想进行更新。 Supposed the page shows/displays the data from mysql into the text fields after i click edit on the view page. 假设在我单击视图页面上的编辑后,页面将mysql中的数据显示/显示到文本字段中。 But the data seemed can't be pulled into the text fields. 但是数据似乎无法拉入文本字段。 Here's my codes for parcelEdit.php 这是我的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>

And this is my parcelView.php codes 这是我的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>

I don't know what/which to be fixed please help me as php is new to me i'm still adapting to it. 我不知道要解决的问题/哪个要解决,请帮助我,因为php是我的新手,我仍在适应它。

For edit you create link: 要进行编辑,请创建链接:

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

And in edit file you have: 在编辑文件中,您具有:

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

Don't you really see that once you set email parameter and then you search for parcelID parameter ? 设置email参数然后搜索parcelID参数后,您真的看不到吗?

So your edit link should look: 因此,您的编辑链接应如下所示:

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

ps: your view file is one big mess... you have: ps:您的视图文件非常混乱……您有:

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

And you generate it in loop. 然后循环生成它。 You really should learn some basic html syntax first. 您确实应该首先学习一些基本的html语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM