Jump to content

update images


erok
 Share

Recommended Posts

Hi all,

I have two separate images in phpmyadmin database; files on xampp

able to update

first image alone ,

able to update

two images in two rows.

But unable to update if i wanted to update second image alone.

 

<form enctype="multipart/form-data" method="post" action="dakgooduy.php" >

.
.
.
$abc = "SELECT id, type, caption FROM dakimages WHERE pid=".$pid." ORDER BY id" or die();
$rs = mysqli_query($con, $abc) ;
$icount=mysqli_num_rows($rs) ;
for($i=0;$i<$icount;$i++) {
$row=mysqli_fetch_array($rs) ;
$type=$row['type'] ;
$nid= $row['id'] ;
$caption=$row['caption'] ;

echo $nid ;

.

.

I use checkbox value="$nid" to transfer image id to to upload file.

UPDATE:<input type="checkbox" name="up[]" value="<?php echo $nid=$row['id'] ; ?>" />

 

In upload file "dakgooduy.php"

 

$icount = 2 ;
for($i=0;$i<$icount;$i++) {
if (!isset($_POST['up'])) $formOk = false ;
$path = $_FILES['image']['tmp_name'][$i] ;
if (filesize($path) > 2000000 or filesize($path) < 1)
{
$formOk = false; //// something wrong here
echo " form ok false " ;
}
else {
$type = $_FILES['image']['type'][$i] ;
$caption = $_POST['caption'][$i] ;
$nid=$_POST['up'][$i] ;

 

What might cause this problem?

Any conceptual help greatly appreciated

 

Link to comment
Share on other sites

Hi,

I got the following errors. Sounds like i am able to bring (image id) $nid from the form page to here. Somehow this page does not recognize $nid

I am trying to bring array $nid

Warning: strlen() expects parameter 1 to be string, array given in C:xampphtdocsdakgooduy.php on line 149form ok false
/* line 149 / if (!empty($_POST['up']) && isset($_POST['up']) && (strlen($_POST['up']) <= 3) && !empty($_FILES['image']) && isset($_POST['image']) || isset($_POST['caption']))
{

 

$formOk = true ;

 

.

.

 

Notice: Undefined offset: 1 in C:xampphtdocsdakgooduy.php on line 166NULL

 

/* line 166 / $nid=$_POST['up'][$i] ;

/* line 167 / var_dump($nid) ;

 

I defined $nid= array() ; earlier on the dakgooduy.php

 

Any comment appreciated

Link to comment
Share on other sites

If $_POST['up'] is an array then you can't use strlen() on it.

 

It looks like $i is 1 and there's no element 1 in the $_POST['up'] array. Where is $i being set?

Link to comment
Share on other sites

Hi Ingolme

I use checkbox value="$nid" to transfer image id to to upload file.

UPDATE:<input type="checkbox" name="up[]" value="<?php echo $nid=$row['id'] ; ?>" />

so it is coming from checkbox.

Link to comment
Share on other sites

" So then $_POST['up'] will be an array of checkbox values that were selected. You should start by looping through $_POST['up'] to get each ID value and process the uploaded file from there. "

if i want to update two pictures i update both of the pictures. If i want to update first picture only i can update first picture only. I can not update second pictures only.

if you look at my first post you can see my codes i m looping through already.

Link to comment
Share on other sites

sorry i made it looks like a little bit ambiguous.

following code is part of the for loop on the first post

// use checkbox value="$nid" to transfer image id to to upload file.

UPDATE:<input type="checkbox" name="up[]" value="<?php echo $nid=$row['id'] ; ?>" />

I can updates two images no problem i got following message with var_dump function

string(1) "9" string(2) "10"

when i tried second image only i got following messege

Notice: Undefined offset: 1 in C:xampphtdocsdakgooduy.php on line 166

NULL

Link to comment
Share on other sites

I got the following message with phpinfo() function
when i tried to update second image. its picture id=2 in database
Apache Environment
REQUEST_METHOD POST
QUERY_STRING no value
REQUEST_URI /dakgooduy.php
SCRIPT_NAME /dakgooduy.php
HTTP Headers Information
HTTP Request Headers
HTTP Request POST /dakgooduy.php HTTP/1.1
Accept text/html, application/xhtml+xml, */*
PHP Variables
Variable
Value
_REQUEST["title"] NEW HOPE 501
_REQUEST["country"] USA
.
.
_REQUEST["MAX_FILE_SIZE"] 2000000
_REQUEST["caption"] Array
(
[0] => asli 328 211
[1] => bill 328 502
)
_REQUEST["up"] Array
(
[0] => 2
)
_REQUEST["kitchen"] update
_POST["title"] NEW HOPE 501
.
.
_POST["MAX_FILE_SIZE"] 2000000
_POST["caption"] Array
(
[0] => asli 328 211
[1] => bill 328 502
)
_POST["up"] Array
(
[0] => 2
)
_POST["kitchen"] update
_FILES["image"] Array
(
[name] => Array
(
[0] =>
[1] => _70132432_vikingship.jpg
)
[type] => Array
(
[0] =>
[1] => image/jpeg
)
[tmp_name] => Array
(
[0] =>
[1] => C:xampptmpphp5153.tmp
)
[error] => Array
(
[0] => 4
[1] => 0
)
=> Array
(
[0] => 0
[1] => 59725
)
)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...