Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

can someone tell me why this is not setting the session variable?

New Here ,
Aug 24, 2006 Aug 24, 2006
first page

<?php
// script1.php
session_start();
echo "<form action=\"script2.php\" method=\"post\" name=\"name1\">";
echo "Your name: <input name=\"name\" type=\"text\" size=\"20\" value=\"\">  ";
echo "<input name=\"submit\" type=\"submit\" value=\"Submit\">";
echo "</form>";
?>

second page

<?php
// script2.php
session_start();
echo('Hello, ' . $_SESSION['name1']);
?>
TOPICS
Server side applications
283
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2006 Aug 24, 2006
LATEST
jlw12689 wrote:
> second page
>
> <?php
> // script2.php
> session_start();
> echo('Hello, ' . $_SESSION['name1']);
> ?>

You need to set the session variable first.

<?php
session_start();
if (isset($_POST['name1'])) $_SESSION['name1'] = $_POST['name1'];
echo 'Hello, ' . $_SESSION['name1'];
?>

By the way, using echo to create your form on page one is a complete
waste of time. Just use an ordinary HTML form - a lot less typing, and a
lot more efficient.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines