Jump to content

how to pass variable to other page


madhmad

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/234255-how-to-pass-variable-to-other-page/
Share on other sites

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"];
?>

 

 

 

 

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.