Jump to content

*solved* PHP Variable passing (I should be embarrassed)


laide234

Recommended Posts

Please take a look at my code below. I would like to pass the variable in $autoNum to whichever of the php pages are loaded (edit, add or delete). 

autoNum is the primary key


[code]<?php
switch ($view) {
case 'edit' :
$content = 'edit.php';
break;

case 'add' :
$content = 'add.php';
break;

case 'delete' :
$content = 'delete.php';
break;

default :
$content = 'edit.php';
}
?>

      <td width="50%" colspan="2">
<?php
echo $autoNum;
require_once $content;
?>[/code]


How do I send $autoNum to the requested page. :-[
If you are including/requiring scripts then any variables you have set in the script that is including/requiring the files can be using in the included/required script.

Eg:
[b]test.php[/b]
[code=php:0]<?php

$varname = 'Hello world';

// include test2.php
// we'll be able to use the variable set above in test2.php
include 'test2.php';

?>[/code]


[b]test2.php[/b]
[code=php:0]<?php

// show the value of $varname.
// this will use the variable we set in test.php
echo $varname;

?>[/code]


When you go to test.php you should get Hello World printed to the screen.

When using include/require what PHP is affectively doing is basically getting the contents of the required script and pasting it in the location of where the file gets included to as though the code was already there. For example, think of test.php being like this when you run test.php
[code=php:0]<?php

$varname = 'Hello world';

// include test2.php
// we'll be able to use the variable set above in test2.php

// show the value of $varname.
// this will use the variable we set in test.php
echo $varname;

?>[/code]

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.