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

 

 

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.