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

 

 

Link to comment
Share on other sites

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

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.