更新表单不填充mysql数据库中的现有数据

时间:2014-11-12 19:58:31

标签: php mysqli

您好我试图用来自mysql数据库的现有数据填充我的Update表单,这样我就可以修改数据并将其保存回mysql数据库。一切正常,没有错误,但根本没有填充。提前致谢

的index.php

<?php
require('includes/mysqli_connect.php');
$query = "SELECT * FROM item";
$result = mysqli_query($dbc, $query);
WHILE($items = mysqli_fetch_array($result)) {
    echo "<h3>" . $items['item_id'] . "</h3>";
    echo "<p>" . $items['title'] . "</p>";
    echo "<a href=\"modify.php?id=" . $items['item_id'] . "\">Modify Item</a>";
    echo "<span> </span>";
    echo "<span> </span>";  
    echo "<a href=\"delete.php?id=" . $items['item_id'] . "\">Delete Item</a>";
}
?>

Modify.php

<?php 
require('includes/mysqli_connect.php');
if(!isset($_POST['submit'])) {  
include('includes/mysqli_connect.php');         
$q = "SELECT * FROM item WHERE item_id = '$_GET[item_id]'";
$result = mysqli_query($dbc, $q);
$items = mysqli_fetch_array($result)
 /* or die("Error: ".mysqli_error($dbc)) */;
}
?>
<h1>Modify item</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">        
<h4>Selling format:</h4>
<h4>Auction:
<input type="checkbox" value="<?php echo $items['auction']; ?>" name="inputauction"></h4>       
<h4>Buy Now:
<input type="checkbox" value="<?php echo $items['buynow']; ?>" name="inputbuynow"></h4>
<h4>Select category:</h4>   
<select name="cat_id"> 
<?php
include('includes/mysqli_connect.php');
$q = "SELECT cat_id, cat_name FROM category ".
"ORDER BY cat_id";
$r = mysqli_query($dbc,$q);
while($row = mysqli_fetch_array($r))
{ 
echo "<option value=\"".$row['cat_id']."\">".$row['cat_name']."</option>\n  ";
}
?>
</select>   
<h4>Title:
<input type="text" size="30" maxlength="30" 
value="<?php echo $items['title']; ?>"   name="inputtitle"></h4>    
<h4>Description:</h4>
<textarea rows="7" cols="27" value="<?php echo 
$items['description']; ?>"  name="inputdescription" wrap="physical"></textarea> 
<p><a href="#" onclick="window.open('uploadwin.php', 'newwindow', 
'width=200, height=150'); return false;">
<h4>Click here to upload picture</h4></a></p>
<h4>Auction Start Price:
<input type="text" size="15" maxlength="15" 
value="<?php echo $items['auct_price']; ?>" name="inputauct_price"></h4>    
<h4>Buynow Price:
<input type="text" size="15" maxlength="15" 
value="<?php echo $items['buynow_price']; ?>" name="inputbuynow_price"></h4>
<h4>Duration:
<select name="inputduration">
<option value="<?php echo $items['1 Day']; ?>">1 Day</option>
<option value="<?php echo $items['3 Days']; ?>">3 Days</option>
<option value="<?php echo $items['5 Days']; ?>">5 Days</option>
</select></h4>  
<h4>Quantity:
<input type="text" size="15" maxlength="15" 
value="<?php echo $items['qty']; ?>" name="inputqty"></h4>
<h4>Item Location:
<input type="text" size="15" maxlength="15" 
value="<?php echo $items['item_location']; ?>" name="inputitem_location"></h4>      
<h4>Accepted Payment:</h4>  
<h4>PayPal:
<input type="checkbox" value="<?php echo $items['paypal']; ?>" name="inputpaypal"></h4>     
<h4>EFT:
<input type="checkbox" value="<?php echo $items['EFT']; ?>" name="inputEFT"></h4>   
<h4>Postage:</h4>
<h4>Pickup:
<input type="checkbox" value="<?php echo $items['pickup']; ?>" name="inputpickup"></h4>     
<h4>Post Interstate:
<input type="checkbox" 
value="<?php echo $items['post_nationally']; ?>" name="inputpost_nationally"></h4>      
<h4>Post National:
<input type="checkbox" value="
<?php echo $items['post_internation']; ?>" name="inputpost_internation"></h4>       
<h4>Post Internation:
<input type="checkbox" 
value="<?php echo $items['buyerpay_post']; ?>"   name="inputbuyerpay_post"></h4>
<input type="hidden" name="item_id" value="<?php echo $_GET['item_id']; ?>" />      
<input type="submit" value="Modify" name="submit">
</form><br><br>
<?php 
if(isset($_POST['submit'])) {
$u = "UPDATE `ICADBS504A`.`item` SET `auct_price` = '$_POST[inputauct_price]', 
`buynow_price` ='$_POST[inputbuynow_price]', `title` = '$_POST[inputtitle]', 
`description` =  '$_POST[inputdescription]', `qty` = '$_POST[inputqty]', 
`img_path` = '$imgpath',  `item_location` = '$_POST[inputitem_location]',         
`auction` = '$_POST[inputauction]', `buynow` = '$_POST[inputbuynow]', 
`duration` = '$_POST[inputduration]', `pickup` = '$_POST[inputpickup]', 
`post_nationally` = '$_POST[inputpost_nationally]', 
`post_internation` = '$_POST[inputpost_internation]', 
`buyerpay_post` = '$_POST[inputbuyerpay_post]', `cat_id` = '$cat', 
`paypal` = '$_POST[inputpaypal]', `EFT` =  '$_POST[inputEFT]' WHERE 
`item_id` = $_POST[item_id]";
mysqli_query($u) or die(mysqli_error());
echo "Item has been modified!";
header("Location: index.php");
}
include('includes/footer.html'); 
?>

0 个答案:

没有答案