laide234 Posted September 13, 2006 Share Posted September 13, 2006 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. :-[ Quote Link to comment https://forums.phpfreaks.com/topic/20611-solved-php-variable-passing-i-should-be-embarrassed/ Share on other sites More sharing options...
scottybwoy Posted September 13, 2006 Share Posted September 13, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/20611-solved-php-variable-passing-i-should-be-embarrassed/#findComment-91006 Share on other sites More sharing options...
wildteen88 Posted September 13, 2006 Share Posted September 13, 2006 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.phpinclude '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.phpecho $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.phpecho $varname;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20611-solved-php-variable-passing-i-should-be-embarrassed/#findComment-91018 Share on other sites More sharing options...
laide234 Posted September 13, 2006 Author Share Posted September 13, 2006 ::) 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. Quote Link to comment https://forums.phpfreaks.com/topic/20611-solved-php-variable-passing-i-should-be-embarrassed/#findComment-91022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.