anf.etienne Posted February 17, 2009 Share Posted February 17, 2009 is it possible to transfer variables from 1 file to another? for example is you go to http://www.ve-creative.com/test/8/templateEdit.php at the bottom where it says upload new image and click the form will appear and you can upload....from then it will submit to a php file, i have set it so that it prints the location of the uploaded files so i know its working. After uploading the images i want to redirect it back to the original page. In the original page. I have created a variable with the full location of where the images are uploaded to but need to know how i can get that variable from 1 file to the other without the use of mysql....is this possible? thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/ Share on other sites More sharing options...
cola Posted February 17, 2009 Share Posted February 17, 2009 Yes you do on the next way <?php $id= 1; header ("Location file.php?id=$id"); file.php need to have only one line echo $_POST['$id']; Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764184 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 thanks a lot i will test it now and let you know the results Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764187 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 i have just got the following message Warning: Cannot modify header information - headers already sent by (output started at /home/vecre0/public_html/test/8/addimgck.php:10) in /home/vecre0/public_html/test/8/addimgck.php on line 67 here is my coding....what have i done wrong? <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple image upload script from plus2net.com</title> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <? $random_digit=rand(0000000000,9999999999); $folderIn=mkdir("upload/$random_digit", 0777); ?> <? while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upload/$random_digit/$filename"; //echo $_FILES['images']['type'][$key]; // echo "<br>"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); $full_path="http://ve-creative.com/test/4/$random_digit/$filename<br />"; $folderPath="http://ve-creative.com/test/4/$random_digit"; } } $id= "$random_digit"; header ("Location templateEdit.php?id=$id"); ?> <? $username="vecre0_tempU"; $password="auction"; $database="vecre0_templates"; // OPEN CONNECTION ---> $connection=mysql_connect("localhost","$username", "$password") or die("Unable to connect!"); mysql_select_db("$database") or die("Unable to select database!"); // EXECUTE QUERY ---> $query="INSERT INTO paths ( folderPath) VALUES( '".$folderPath."')"; //////-----> $result=mysql_query($query) or die("Error in query:".mysql_error()); //if ($result) //echo mysql_affected_rows()." row inserted into the database effectively."; // CLOSE CONNECTION ---> mysql_close($connection); ?> <?php ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764212 Share on other sites More sharing options...
cola Posted February 17, 2009 Share Posted February 17, 2009 u ca not send header if u have any echo before but from your code i soupse that u want inlude some pph file u can d on this way. <?php $id=1; include "file.php"; ?> in file.php u nedd to do echo $id Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764213 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 ok its worked but now it has enlarged all the text and text boxes on my page even when i've add the css files to the coding i previously showed you it does nothing Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764237 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 what is the best way to transfer variables from 1 php fle to another? Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764341 Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 To address you main issue: header ("Location templateEdit.php?id=$id"); Is after data was outputted to the screen. Read header for more information. To fix it, you should have your output as the last item (or at least after header calls) in your script, not inter-mixed because of this very issue. Your code needs to be re-thought and corrected. The other option is ob_start which is a bandaid for the real issue. Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764350 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 hi im a newbie at all this, i just needed a simple way to pass a random generated number from 1 page to the next and once it submitted for that number to go back to the 1st page so i can continue to use it. i have been reading different sites and forums and so far i think session, get or post might be the best solution....i have no data that i want to protect. I am just wary of how to actually get them to pass the variable to the submit page and back to the 1st page once it redirects back Quote Link to comment https://forums.phpfreaks.com/topic/145563-variables/#findComment-764371 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.