簡體   English   中英

我也要編輯要上傳的圖像和產品名稱

[英]I want to edit images and product name also that i am uploading

這是我的index.php文件

<?php
require_once('../admin/constant.php');
$host="localhost"; // Host name
$username="***"; // Mysql userna
$password="*****"; // Mysql password
$db_name="***"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$result=mysql_query("SELECT * FROM users ORDER BY id DESC");
?>

<html>
<head>
<title>Homepage</title>

</head>


<body>
<a href="add.php">Add New Data</a><br/><br/>
<?php
echo "<table width='80%' border=0 align='center'>";
echo "<tr bgcolor='#CCCCCC'>";
echo "<td>Product Name</td>";
echo "<td>Normal Image</td>";
echo "<td>Selected Image</td>";
echo "<td>Update</td>";
echo "</tr>";
while($res=mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>".$res['name']."</td>";
        ?>
    <td>
<?php     
$handle = opendir(dirname(realpath(__FILE__)).'/images/');
echo '<img style="height:50px; width="20px;"" src="upload/product/'.$res['id'].'/'.$res['image'].'" border="0" />'; 
?></td>
<td>
<?php     
$handle = opendir(dirname(realpath(__FILE__)).'/images/');
echo '<img style="height:50px; width="20px;"" src="upload/product/'.$res['id'].'/'.$res['image1'].'" border="0" />'; 
?></td>

<?php 

echo "<td><a href=\"edit.php?id=$res[id]\">Edit</a> | <a href=\"delete.php?id=$res[id]\">Delete</a></td>";

}
echo "</table>";
?>

這表明我的產品名稱及其圖像列表問題是,當我單擊“編輯”鏈接時,編輯不起作用意味着名稱,圖像未更新,請引導我。 以下是我的edit.php

<?php
require_once('../admin/constant.php');  
error_reporting(0);//including the database connection file
$host="localhost"; // Host name
$username="***"; // Mysql username
$password="***"; // Mysql password
$db_name="***"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

if(isset($_POST['update']))
{
    $ProdImg        = false;
    $ProdIcon       = false;
    $id             = $_POST['id'];
    $pic_name_hid   = $_POST['hidimage'];//product icon
    $pic_name_hid1  = $_POST['hidimage1'];//seelct image
    $name           = $_POST['product_name'];
    $sql            = "update users set name='$name',image ='$pic_name_hid',image1='$pic_name_hid1' where id=$id";
    echo $sql;
    $res            = mysql_query($sql);
    header("Location: index.php");

    if($_FILES['product_icon']['name'] == "")
        {
            $ProdImg                    = true;
            $picture_filename           = $_POST['hidimage'];
            $data_all["image"]          = $_POST["hidimage"];

            print_r($data_all);
        }
    if($ProdImg == false) { 
            $image          = $_FILES['product_icon']['name'];

            $extension      = substr(strrchr($image, '.'), 1);
            $port_tmp_name  = $_FILES['product_icon']['tmp_name'];
            $result         =mysql_query("SELECT * FROM users WHERE id=$id");
            $obj            =mysql_fetch_object($result);

            print_r($obj);
            $icon_nm            = $obj->id.".".$extension;

            $sql="UPDATE users SET name='$name',image='$icon_nm',image1='$pic_name_hid1' WHERE id=$id";
            $result=mysql_query($sql);
            if(is_dir(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id)) 
            {
                    mkdir(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id);
                    move_uploaded_file($port_tmp_name, SITE_UPLOAD_PRODUCT_PATH.$obj->id."/".$icon_nm);
                    unlink(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id);
                    move_uploaded_file($selected_tmp_nm, SITE_UPLOAD_PRODUCT_PATH.$obj->id."/".$icon_nm);
                    unlink(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id);
                    header("Location: index.php");exit;
            }
        }


    $image          = $_FILES['product_icon']['name'];
    $extension      = substr(strrchr($image, '.'), 1);
    $port_tmp_name  = $_FILES['product_icon']['tmp_name'];

    $image1             =$_FILES['select_image']['name'];   
    $extension_img      = substr(strrchr($image1, '.'), 1);
    $selected_tmp_nm    = $_FILES['select_image']['tmp_name'];

    else
    {   
        //updating the table
        $result=mysql_query("SELECT * FROM users WHERE id=$id");
        $obj    =mysql_fetch_object($result);

        $icon_nm            = $obj->id.".".$extension;
        $selected_nm        = $obj->id."_selected.".$extension_img;

        $sql="UPDATE users SET name='$name',image='$icon_nm',image1='$selected_nm' WHERE id=$id";
        $result=mysql_query($sql);
        if(is_dir(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id)) 
        {
                mkdir(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id);
                move_uploaded_file($port_tmp_name, SITE_UPLOAD_PRODUCT_PATH.$obj->id."/".$icon_nm);
                unlink(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id);
                move_uploaded_file($selected_tmp_nm, SITE_UPLOAD_PRODUCT_PATH.$obj->id."/".$selected_nm);
                unlink(SITE_UPLOAD_PRODUCT_PATH."/".$obj->id);
}
        //redirectig to the display page. In our case, it is index.php
        header("Location: index.php");
    }
}
?>
<?php
//for displaying data of this particular data

//getting id from url
$id = $_GET['id'];

//selecting data associated with this particular id
$result=mysql_query("select * from users where id=$id");

while($res=mysql_fetch_object($result))
{

     $tid=$res->id;
     $name = $res->name;
     $image = $res->image;
    $image1 = $res->image1;
}
?>
<html>
<title>Edit Data</title>
<body>
<a href="index.php">Home</a>
<br/><br/>
<form name="form1" method="post" action="edit.php" enctype="multipart/form-data">
<table border="0" align="center">

  <tr> 
      <td>Product Name</td>
      <td><input type="text" name="product_name" id="product_name" value="<?php echo $name;?>"><span style="color:Red; "></span></td>
      &nbsp;<td ><span id="errproduct_name" style="width:50px;"></span> </td>

    </tr>

  <tr> 
      <td>Normal Images</td>
      <td><input type="file" name="product_icon" id="product_icon" value="<?php echo $image;?>">
      <span style="color:Red;"></span></td>
      <td><?php if($image != '') {  echo "<br>";?>
          <img src="<?php echo SITE_UPLOAD_PRODUCT_URL. $tid."/" .$image; ?>" width="50px" height="60px"  /><br>
          <?php } ?>
      </td>
      <td ><span id="errproduct_icon"></span></td>
   </tr>
<tr> 
      <td>Selector Images</td>
      <td><input type="file" name="select_image" id="select_image" value="<?php echo $image1;?>/><span style="color:Red;"></span></td>
      <td><?php if($image1 != '') {  echo "<br>";?>
          <img src="<?php echo SITE_UPLOAD_PRODUCT_URL. $tid."/" .$image1; ?>" width="50px" height="60px"  /><br>
          <?php } ?>
      </td>
      <td ><span id="errselect_image"></span></td>
    </tr>
<tr>
    <td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>>  
    <input type="hidden" name="hidimage" id="hidimage" value=<?php echo $image?>> 
     <input type="hidden" name="hidimage1" id="hidimage1" value=<?php echo $image1?>>  </td>
    <td><input type="submit" name="update" value="Update"></td>
  </tr>
</table>
</form>

</body>
</html>

PLZ給我EDIT.PHP的代碼:(

如果我在這很晚才正確閱讀您的代碼-而不是:

“更新用戶設置名稱='$ name',圖像='$ pic_name_hid',圖像1 ='$ pic_name_hid1',其中id = $ id”;

嘗試這個:

“ UPDATE用戶SET name ='”。 $ name。 “',image ='”。 $ pic_name_hid。 '“,image1 ='”。 $ pic_name_hid1。 '“ WHERE id ='”。 $ id。 '“;

我假設您已經檢查過您的POST變量確實得到正確傳遞(打字錯誤等)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM