dsijovl015728613 2013-10-29 04:45
浏览 17
已采纳

当脚本执行PHP / MySQL时失去变量值

My GET value is fine on first if statement but when it hits update_submit I get an undefined variable error. This is still test script so there's no validation

 <?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>
  • 写回答

1条回答 默认 最新

  • down_load1117 2013-10-29 04:49
    关注

    If coming from the same form, are you mixing $_GET and $_POST settings for your form? You have the value when using ($_GET['pid']), but not when using ($_POST['update_submit']).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重