我的GET
值在第一個if
語句上沒有問題,但當它碰到update_submit
時,我得到一個undefined variable
錯誤。這仍然是測試腳本,所以沒有驗證腳本執行時丟失變量值PHP/MySQL
<?php
session_start();
include "connect.php";
error_reporting(E_ALL);
ini_set('display_errors','1');
if(isset($_GET['pid']))
{
$get_item = $_GET['pid'];
echo "pid" . $get_item;//<--has value here
$get_products = $db->prepare("select * from `item` where
`item_id` = '$get_item' LIMIT 1");
$get_products->execute();
while ($row = $get_products->fetch())
{
$user_id = $row['user_id'];
$item_name = $row['item_name'];
$item_description = $row['item_description'];
$image = $row['photopath'];
}
}
echo "pid" .$get_item;//<---has value here
if(isset($_POST['cancel_edit']))
{
header("Location: manage_items.php");
exit();
}
if(isset($_POST['update_submit']))//<<---lose it here
{
$get_products = $db->prepare("select `photopath` from `item` where
`item_id` = '$get_item' LIMIT 1");
$get_products->execute();
$path= $get_products->fetchColumn(6);
FORM
<form action="item_edit.php" method="post" enctype="multipart/form-data">
<input type = "text" name="item_name" value="<?php echo $item_name ?> "/>
<textarea name="item_description"><?php echo $item_description ?></textarea>
<p> <img src="<?php echo $image; ?>" width="75" height="75" /></p>
<input type="file" name="image_edit" value="<?php echo $image ?>"/>
<input name="img_edit" type="hidden" value="<?php echo $image ?>"/>
<input name="edit_form_id" type="hidden" value="<?php echo $get_item ?>">
<p><input type="submit" name="update_submit" value="Update"/></p>
<p><input type="submit" name="cancel_edit" value="Cancel"/></p>
</form>
@Ali更新代碼 – rogerthat