madhmad Posted April 20, 2011 Share Posted April 20, 2011 i knw dis mst a simple question but how to pass variable to other page for eg i hav created a page where user submits username n telephone then via sms some random number goes to user mobile ...i want this random number variable in other page dis is my code for startreg.php <form action="startregprocess.php" method="post"> username:<input type="text" name="username"> telephone<input type="text" name="telephone" <input type="submit" name="submit"> </form> <?php srand ((double) microtime( )*1000000); $random_number = rand( ); echo $random_number; ?> i want tht $random_number in other page called startregprocess.php Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/ Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 you will either need to use session variables to transfer variable values between pages or use the URL of the form action to pass it over to the next page and use $_GET on the target page to pull it into the page content there. Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1203988 Share on other sites More sharing options...
madhmad Posted April 20, 2011 Author Share Posted April 20, 2011 can u pls explain me using either my example or an example of urs Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1203990 Share on other sites More sharing options...
kney Posted April 20, 2011 Share Posted April 20, 2011 yep it's just <?php // Gotta put this on top of every page btw session_start(); ?> <form action="startregprocess.php" method="post"> username:<input type="text" name="username"> telephone<input type="text" name="telephone" <input type="submit" name="submit"> </form> <?php srand ((double) microtime( )*1000000); $random_number = rand( ); echo $random_number; // just use the new variable on the other page $_SESSION["randomnumber"] = $random_number; ?> and do this on the other page to get it <?php session_start(); echo $_SESSION["randomnumber"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1203991 Share on other sites More sharing options...
madhmad Posted April 20, 2011 Author Share Posted April 20, 2011 hey thanks for ur reply ......lets see how it works Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1203997 Share on other sites More sharing options...
madhmad Posted April 20, 2011 Author Share Posted April 20, 2011 kney: hey sory but dis is not working my form submission code is <form action="startregprocess.php" method="post"> username:<input type="text" name="username"> telephone<input type="text" name="telephone"> <input type="submit" name="submit" value="Submit" /> </form> <?php srand ((double) microtime( )*1000000); $random_number = rand( ); echo $random_number; // just use the new variable on the other page $_SESSION["randomnumber"] = $random_number; ?> and startregprocess code is <?php session_start(); echo $_SESSION["randomnumber"]; ?> <?php include("connect.php"); $username=$_POST['username']; $telephone=$_POST['telephone']; $user_id=$_SESSION['randomnumber']; $sql=mysql_query("INSERT INTO reg (username,telephone,random) VALUES('$username','$telephone','$user_id') "); if($sql) { echo 'your complaint has been submitted and the complaint id is '; } ?> its echoin your complaint has been submitted n all but d problem is d random number generated is not goin in database table reg Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1204006 Share on other sites More sharing options...
kney Posted April 20, 2011 Share Posted April 20, 2011 did you also use the session start on ur first page? Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1204011 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 without going into the lack of wizdom in storing randomised numbers in this scenario, you will need to start the page (as is the verry fist line) with <?php session_start(); ?> . Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1204014 Share on other sites More sharing options...
madhmad Posted April 20, 2011 Author Share Posted April 20, 2011 thts so swt of u guys .it worked.....thankkkkkks a lottt Quote Link to comment https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/#findComment-1204016 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.