0

I have a simple question, with maybe not so simple of an answer. I want to be able to set a variable in one script and pass that value and variable to another script. Without passing it through the url, and having the ability to pass an array.

So I have index.php in there I have a variable

<?php
$myvariable = '';
<form action=editRecord.php>
do some form actions here and submit moving to editRecord.php
</form>
?>

Now in editRecord.php

<?php
header('Location: go back to index.php);
run functions and edit the Mysql DB
//Ok now here is where I want to assign a value to $myvariable and pass it back to index.php
?>

Is this possible? I am sorry for the amateurish question, but I am very green when it comes to php.

Thank You.

1
  • Can you use sessions? Commented Jun 3, 2014 at 19:55

3 Answers 3

1

you can set it in the $_SESSION variable:

<?php
session_start();
$_SESSION["myVar"] = "blabla";
....

Of course you can store an array() in this variable too.

Sign up to request clarification or add additional context in comments.

Comments

0

Just pass that information in the querystring. Then you can access it via $_GET. If it doesn't exist, just set the value to an empty string or whatever default value you want it to have.

// editRecord.php
<?php
// do db dtuff
header('Location: index.php?myvariable=somevalue');
?>

// index.php
<?php
$myvariable = (isset($_GET['myvariable'])) ? $_GET['myvariable'] : '';
<form action="editRecord.php" >

</form>
?>

You can also use session variables:

// editRecord.php
<?php
session_start();
// do db stuff
$_SESSION['myvariable'] = 'somevalue';
header('Location: index.php');
?>

// index.php
<?php
session_start();
$myvariable = (isset($_SESSION['myvariable'])) ? $_SESSION['myvariable'] : '';
<form action="editRecord.php" >

</form>
?>

1 Comment

ok, The $_SESSION[] seems to be good. I have already started a session for the users to login, so presumably I wouldn't need to start another one right?
0

You can use sessions, POST data, GET data, cookies and database data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.