Diptopol Dam
Diptopol Dam

Reputation: 815

showing error message in php

want to show a error message as a result of a form action. For example

<form action=a.php
      input .....
</form>
<span.....>
<?php 
    $variable(Initially the value of this variable null according to the result of form value will change)
?>
</span>

For a specific condition I want to set a value of $variable in a.php page and return to form page using header(); . But $variable does not change. How can I change $variable from a.php ?

Upvotes: 0

Views: 100

Answers (3)

tssmid
tssmid

Reputation: 139

Use SESSION variables.

in the head of each document put session_start();

after this you assign the variables you nedd to access across document like this: $_SESSION['variable'];

Define the session variable right before using header(); then insert something like:

if (isset($_SESSION['variable'])){ print $_SESSION['variable']; unset($_SESSION['variable']); }

Upvotes: 1

Shomz
Shomz

Reputation: 37711

The question is not quite clear, but sounds like you need this:

if(isset($variable) AND $variable != '') echo "<span>$variable</span>";

Upvotes: 1

lanzz
lanzz

Reputation: 43198

PHP variables are not persistent, when you redirect the browser to another location, your script's execution is terminated and you lose all of your variables and their values. Read about session handling in the PHP documentation for a way to store persistent data between requests.

Upvotes: 2

Related Questions