Jump to content

Reg vars


dasein

Recommended Posts

Hi, I'm trying to sort out what's deprecated in passing a variable from .php page to .php page. I'm getting more and more confused trying to sort it all out. I've got three files (test.html, test1.php, test2.php). I've been toying with different things but can only get a variable from the html page to show up in test1.php. It won't pass though to test2.php and I've tried about every variant I can find from tutorials and such.

 

THE HTML FILE:

 

<html>

<head><title>TEST</title>

</head>

 

<body bgcolor="#ffffff">

<center><p>

 

<form name="test" action="test1.php" method="post">

 

Name: <input type=text name=username><p>

 

</center>

<input type=submit value="SUBMIT"> <input type=reset value="RESET ALL">

</form>

 

 

</body>

</html>

 

THE test1.php FILE:

 

<?php

session_start();

 

$username = isSet($_POST['username']) ? $_POST['username'] : '';

$_SESSION['username'] = $username;

 

//echo "USERNAME: $username<p>";

 

session_register('username');

header("location: test2.php");

 

?>

 

THE test2.php FILE:

 

<?php

session_start();

 

echo "USERNAME in TEST2:$username<p>";

 

?>

Link to comment
Share on other sites

Your coding is all messed up. Please if you post as well use the code tag if you post code.  Here is an example

 

index.html

<html>
<body>
<form method="post" action="index.php">
Name:
<input type="text" name="username">
</form>
</body>
</html>

 

index.php

<?php
//set the variable $username from the form
$username = $_POST['username'];

//write the variable to the page
echo $username;
?>

 

This is a pretty basic example. Please let me know if this helps.

Link to comment
Share on other sites

don't use session_register(). You can remove that line as you already set the session variable with $_SESSION['username'] = $username;

 

You call it by the same variable: $_SESSION['username']; so make it..

<?php
session_start();

echo "USERNAME in TEST2:$_SESSION['username']";
?>

 

If you enable E_NOTICE it warns you if you use a depreciated function.

Link to comment
Share on other sites

Hey thanks...that does work. I haven't done much in a few years and am amazed at the modifications they've introduced. I guess I should go back to square one and learn from scratch again how things are properly coded...thanks again!

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.