kev wood Posted May 12, 2008 Share Posted May 12, 2008 i am have generated a random number to add to a image file so that it cannot show a cached version of the image when the pages are entered again. i have a form to upload an image in an iframe held on one of the pages in the web site. i want to post the random number across to other pages so that it can be used to add to the image file once more to display the image. i have tried to post the information from the upload image form but i cannot get the value of the $rand variable to come through to the next page. the code i have used is as follows <form name="newad" method="post" enctype="multipart/form-data" action=""> <input type="hidden" value="<?=$rand;?>" name="rand" /> <input type="file" name="broad1_image" > <input name="Submit" type="submit" id="image1" value="Upload image" > </form> and to retrieve the number on the next page i have used $rand=$_POST['rand']; Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/ Share on other sites More sharing options...
jaymc Posted May 12, 2008 Share Posted May 12, 2008 print_r($_POST); What do you get? Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-538932 Share on other sites More sharing options...
dymon Posted May 12, 2008 Share Posted May 12, 2008 Try adding in the action attribute the name of the php file that will handle the form, of course if it's not the same file. Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-538946 Share on other sites More sharing options...
kev wood Posted May 12, 2008 Author Share Posted May 12, 2008 jaymc if i put the print in it gives me nothing. dymon if i put an action attribute with the value of the page that i want the data posted to will it not direct the user to the page when the submit button is pressed. if this is true then i cannot use this as the user has the oppurtinity to upload other images on the same page. I was going to use the get but as the images are uploaded on an iframe then this would not append the value to the url when the links are pressed to move to the next page Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-538952 Share on other sites More sharing options...
kev wood Posted May 12, 2008 Author Share Posted May 12, 2008 jaymc when i replied to the print_r when i said i get nothing i did not mean completely nothing just nothing for the variable to $rand. this obviously means that the value of the variable is not getting posted through so it cannot be accessed from any other page. Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-538969 Share on other sites More sharing options...
kenrbnsn Posted May 12, 2008 Share Posted May 12, 2008 You are using the short tags short hand here: <input type="hidden" value="<?=$rand;?>" name="rand" /> unless you have short tags turned on, this will not work. Write is as <input type="hidden" value="<?php echo $rand;?>" name="rand" /> Also, is the form in a file with the extension ".php", if it is not, then this won't work. Ken Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-538987 Share on other sites More sharing options...
kev wood Posted May 12, 2008 Author Share Posted May 12, 2008 yes it is on a php page. with the echo in there will this then post the value of the $rand variable. thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-538998 Share on other sites More sharing options...
kev wood Posted May 12, 2008 Author Share Posted May 12, 2008 i have tried that and i am still not able to recall the the value of the variable rand on the next page. Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539030 Share on other sites More sharing options...
kenrbnsn Posted May 12, 2008 Share Posted May 12, 2008 If you show the source of the web page containing the form, does the value show in the form? Can you post the script that contains the form? Ken Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539130 Share on other sites More sharing options...
kev wood Posted May 13, 2008 Author Share Posted May 13, 2008 the number shows up on the source code. i will upload the code i have got to generate the random number and adding it to the file before it is displayed. also i will upload the code for the form so you can see that as well. I have used forms to post data before and although it was a while ago i am pretty sure it was done in a very similar way and this is why i do not understand why it not working. here is the code anyway. generate random number $rand= rand(0, 100); append to file $broad1name2="image/thumbs/thumb_".$image_name . $rand; form for the upload of the file <form name="newad" method="post" enctype="multipart/form-data" action=""> <input type="hidden" value="<?php echo $rand;?>" name="rand" /> <input type="file" name="broad1_image" > <input name="Submit" type="submit" id="image1" value="Upload image" > </form> all this takes place within an iframe. Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539748 Share on other sites More sharing options...
kenrbnsn Posted May 13, 2008 Share Posted May 13, 2008 Can you post more of you code? The snippets you've posted look fine, so the problem must be somewhere else. Ken Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539774 Share on other sites More sharing options...
kev wood Posted May 13, 2008 Author Share Posted May 13, 2008 which parts of the code would you like me to upload? could it have something to do with the fact iam trying to post this data from within an iframe? Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539776 Share on other sites More sharing options...
kenrbnsn Posted May 13, 2008 Share Posted May 13, 2008 Not knowing your code, I wouldn't know which parts you need to post. What you can try to do is write a small test script that has the same structure as your main code. If that has the same problems, post that. If it doesn't, figure out why one works and the other doesn't. Ken Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539779 Share on other sites More sharing options...
kev wood Posted May 13, 2008 Author Share Posted May 13, 2008 i tested it and it would not work again. i have gone down a different route now, it was taking up to much time to get that working. i am storing the number in a mysql db now and am trying to append it back onto the image when i need to display it again. just not sure if the variable i set to equal the mysql query still has the value when it is used outside of the mysql. will work that out soon enough though. thanks for all your help. Link to comment https://forums.phpfreaks.com/topic/105258-posting-data/#findComment-539952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.