tryingtolearn Posted February 10, 2007 Share Posted February 10, 2007 Hi again all, I am having a problem with getting all of the variables created in a for loop to pass to another form. I will try my best to walk through this - An example of the problem is located at http://www.acmaine.com/select.php I am making a form to upload images, resize them, then place them in a "Click to enlarge gallery" All is going good until I try to display the gallery, I dont get all of the images to pass through to the final page - Only the last one selected. Page 1 to select the # of fields -This works <form action='upload.php' method='post'> Give your gallery a title:<br> <input name="title" type="text" value="Your Gallery Title"><br><br> Select the number of files to upload:<br> <select name='num' /> <?php for($i = 1; $i <= 20; $i++) { echo "<option value=".$i.">".$i."</option><br>"; } echo'</select><br><input type="submit" value="Next"> '; ?> </form> Page 2 Creates the fields - uploads resizes the images presents a form w/ the resized pics to select what images you want in the gallery and what image should be the main image. (I didnt add all the image function stuff in to hopefully keep this from getting longer than it already is. <?php if (isset($_POST['num'])) { $num = $_POST['num']; $title = $_POST['title']; } else { include 'select.php'; exit(); } if (isset($_POST['selected'])) { echo'<form action="gallery.php" method="post">'; echo'<input name="num" type="hidden" value="'.$num.'">'; echo'<input name="title" type="hidden" value="'.$title.'">'; echo'<table border="0" cellspacing="0" cellpadding="5" width="450">'; echo' <tr>'; echo '<td>Image</td>'; echo '<td>Add To Gallery</td>'; echo '<td>Make Primary Image</td>'; echo '</tr>'; $num = $_POST['num']; for ($x = 1; $x <= $num; $x++) { ***All IMAGE resize stuff here*** echo '<tr>'; echo '<td><img src="'.$site.''.$thumb_img.'"></td>'; echo '<td><input name="thumb_img[]" type="checkbox" value="'.$site.''.$thumb_img.'" checked></td>'; echo'<td><input name="res[]" type="hidden" value="'.$site.''.$resize_img.'"><input type="radio" name="primepic[]" value="'.$site.''.$resize_img.'" /></td>'; } else { echo "<br><br>"; echo "Your image - (".$_FILES['imagefile'.$x]['name'].") is the wrong file type. It needs to be a .jpeg or .jpg.<br>"; echo '<hr size="1" width="50%" align="left">'; } }//echo'The directory to these images is <br>'.$site.''.$filedir.'<br> Would you like to see the dir? '; echo'</tr> </table> <input name="size2" type="hidden" value="'.$size2.'"> <br><input type="submit" value="create"> </form> '; exit(); } ?> <form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <input type='hidden' name='title' value='<?php echo $title; ?>' /> <input type='hidden' name='num' value='<?php echo $num; ?>' /> <?php echo 'Your Title: '.$title.''; echo '<br>Upload your .jpg pictures<br>'; for ($x = 1; $x <= $num; $x++) { ?> Select File: <input type='file' name='imagefile<?php echo $x; ?>' /><br /> <?php } ?> <br><br> <p>Click Upload and your gallery will be created on the next page.<br> <input type='Submit' name="selected" value='Upload' /> </form> Page three Displays the results of the form from the previous page but it only gives me the last thumbnail selected instead of all the thumbnails. This is where I got totally experimental trying to figure out what in the world to do??? <?php foreach($res as $num => $resimg){ $resimg = "<A href=\"#\"; onClick=\"document.new_img.src='$site$resimg'; return false;\">"; } foreach($thumb_img as $num => $thumb){ $thumb = "<IMG src=\"$site$thumb\" width=\"$size2\" border=\"0\"></A>"; } ?> <TABLE width="620" cellpadding="10" border="0" cellspacing="0" align="center"> <TR> <TD width="620" align="center" colspan="2"><P style="font-family: verdana; font-size: 16pt; color: #336699;text-align: center;"><?php echo $title; ?></p></TD> </TR> <TR> <TD align="center" valign="middle" width="400"><IMG name="new_img" src="<?php foreach($primepic as $img){echo $img;} ?>"><br><center><P style="font-size: 8pt; font-family: Arial, Helvetica; color: #666666;">Click an image to the right to enlarge</p></center> </TD> <TD align="center" valign="top" width="170"> <DIV style="scrollbar-arrow-color: #cccccc; scrollbar-base-color: #000000; scrollbar-face-color: #333333; scrollbar-highlight-color: #ffffff; scrollbar-shadow-color: #cccccc; scrollbar-3d-light-color: #ffffff; scrollbar-dark-shadow-color: #ffffff; overflow: auto; width: 140px; height: 300px" align="center"> <?php echo $resimg.$thumb; ?> </DIV> </TD> </TR> </TABLE> Again, you can see a working example of what is happening http://www.acmaine.com/select.php I cant figure out what I need to do where to get all the variables to pass like I get them on page 2 I have been reading Larry Ulmans Book and the php site all morning trying to figure out implode explode foreach ... and my head is spinning. I would appreciate any help on where to go with this problem, Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/37894-solved-problem-getting-all-variables-to-pass-through-forms/ Share on other sites More sharing options...
only one Posted February 10, 2007 Share Posted February 10, 2007 <?php global $your variable; ?> that what you wanted? Quote Link to comment https://forums.phpfreaks.com/topic/37894-solved-problem-getting-all-variables-to-pass-through-forms/#findComment-181429 Share on other sites More sharing options...
tryingtolearn Posted February 10, 2007 Author Share Posted February 10, 2007 Thanks for the reply. Sorry for the confusion but thats what I want where? Quote Link to comment https://forums.phpfreaks.com/topic/37894-solved-problem-getting-all-variables-to-pass-through-forms/#findComment-181433 Share on other sites More sharing options...
tryingtolearn Posted February 10, 2007 Author Share Posted February 10, 2007 Well still confused on the global part, Tried a few different things with that but it didnt change anything. On page 2 everything is done inside of this $num = $_POST['num']; for ($x = 1; $x <= $num; $x++) { blah blah blah } So I get all the images that were uploaded The problem was, if I built the gallery there Every image would be in its one formating - like an individual gallery for each individual pic. Kind of defeated the purpose. Then I realized - apply each one to a form to further enhance things just in case they got a bad resample they dont want to use they can deselect it. So at that point it is reading everything. But when you go to the next page it only gets the last one checked. If it lists Images 1,2,3,4,5 only 5 will show in the gallery. Not sure how to explain it but I hope someone understands what Im saying. Quote Link to comment https://forums.phpfreaks.com/topic/37894-solved-problem-getting-all-variables-to-pass-through-forms/#findComment-181463 Share on other sites More sharing options...
tryingtolearn Posted February 11, 2007 Author Share Posted February 11, 2007 I think my problem was that I was thinking the info was in an array when it wasnt SO once I changed that around (And learned alot more!!) its working now - http://www.acmaine.com/index.html Quote Link to comment https://forums.phpfreaks.com/topic/37894-solved-problem-getting-all-variables-to-pass-through-forms/#findComment-182101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.