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
https://forums.phpfreaks.com/topic/127189-reg-vars/
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
https://forums.phpfreaks.com/topic/127189-reg-vars/#findComment-657921
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
https://forums.phpfreaks.com/topic/127189-reg-vars/#findComment-657922
Share on other sites

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.