Jump to content

Storing and printing variables


drmota

Recommended Posts

Hey,

 

I made a simple form:

 

<html>
<body>
<form action="action.php" method="POST">
<input type="text" name="text" />
<br>
<input type="submit value="submit" />
</form>
</body>
</html>

 

The action.php is as follows:

 

<?php

$text = $_POST['text'];

header('location:next/index.php');

 

next/index.php is as follows:

 

<?php

include_once('../index.html');

echo "Hello, your text was " . $text . "!";
?>

 

Problem: Where the $text variable is located in next/index.php there is a blank space. The php includes the first index.html correctly without errors, but it seems like it doesn't store the variable.

 

Thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/233183-storing-and-printing-variables/
Share on other sites

your bouncing away with the header, try using sessions

session_start(); //must be the first item on script! and on every script!!!!!!

 

$_SESSION['mytext']=$_POST['text']; //before your header bounce :inplace of $text=$_POST[text];

 

<?php
session_start();

include_once('../index.html');

echo "Hello, your text was " . $_SESSION['mytext'] . "!";
?>

 

 

By "It must be on top of every script"

 

You mean any chunk of php which uses this session?

Yes, everywhere you recall $_SESSION variables, u must place the session_start() at the top of the page, or the session will be blank, another way you may use is using $_GET, which sends ur page to index.php?var=example, this can then be defined by $var = $_GET['var']; then you dont need to deal with sessions that messes up in search engine

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.