Jump to content

Archived

This topic is now archived and is closed to further replies.

laide234

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

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. :-[

Share this post


Link to post
Share on other sites
couldn't you use post?  Or put it in a class and use exteds on the following pages.

And while were here, what's case? looked it up in the man, just came up with cos isn't really the same?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
::) Man! I am such a noob.... "(probably simple answer)"  I would have never guessed that I didnt need to pass anything.

Thank a mill', wildteen88.

Share this post


Link to post
Share on other sites

×

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.