1

I've got this code, anyone help on making it work...

while($fetch = mysql_fetch_assoc($query)){

    $image_name = $fetch['image_name'];
    $image_location = $fetch['image_location'];


    <img src="'.$image_location.'"/>

    <input name="image['.$image_id.'][6x7]" type="checkbox" value="'.$image_name.'" /> 6x4
    <br />
    <input name="image['.$image_id.'][8x9]" type="checkbox" value="'.$image_name.'" /> 7x5

}

Display on different page...

foreach($_POST['image'] as $image_id => $name) {

    $uploaded[] = $name;

    echo''.$name.'<br />';


    foreach($name as $size => $size) {

        $uploaded[] = $size;

        echo''.$size.'<br />';

    }
}

Input Script

mysql_query("INSERT INTO table VALUES('', '$name', 'size')");

I am uploading both image name and size (from the checkboxes 6x4, 7x5) I am able to input the size into the database but image name just says Array.

I know this is an obvious fix but I just can't get my head around the multiple arrays is the checkbox values!

Any help of feedback is welcome! HELP!

3
  • Please can you show an examples of your insert query? Commented Feb 25, 2014 at 21:32
  • How about you post all of your code exactly as you have it? There is no way that what you have posted does what you're describing (or anything, for that matter) Commented Feb 25, 2014 at 21:41
  • Please note that mysql_ functions are deprecated Commented Feb 25, 2014 at 22:56

2 Answers 2

2

I assume your $image_location and $image_name are fine so you have correct values on your checkboxes? Otherwise we would need some more details..

Try below to display that correctly then (you're using multidimensional array):

foreach($_POST['image'] as $image_id => $image) {

    foreach($image as $size => $name) {


        $uploaded[] = $name;
        echo''.$name.'<br />';


        $uploaded[] = $size;
        echo''.$size.'<br />';
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Mateusz, Yes I am getting the $image_location no problem and am able to insert that into the database. My issue is simply with $name and $size - which I am still having trouble with, unfortunately your solution didn't work (but thanks for helping)
Can you post what you have on var_dump($_POST['image'])?
array(2) { [2]=> array(1) { ["6x4"]=> string(38) "image1.jpg" } [3]=> array(1) { ["6x4"]=> string(39) "image1.jpg" } } image1.jpg 6x4 image1.jpg 6x4 Home
1
<input name="image['.$image_id.'][]" type="checkbox" value="6x7" /> 6x4
<br />
<input name="image['.$image_id.'][]" type="checkbox" value="8x9" /> 7x5

The value should not be the image name, but the size you specified. You already have the image ID, so why include the filename? You can just extract that from your database again...

Also:

foreach($name as $size => $size) {

... is a bit weird: Using the $size var for key and value? That's asking for trouble. ;)

2 Comments

$size => $size is not "a bit weird", it is just plain wrong. $size will be the be the index, not the related value (which I'm sure is not what is wanted). There is so much wrong with the posted code that I don't even know where to begin.
I know its wrong! If it wasn't wrong I wouldn't be on here, would I (!!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.