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. :-[
Link to comment
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]
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.