Braveheartt Posted March 17, 2008 Share Posted March 17, 2008 Here's my code: <?php require("menu.php"); ?> <?php if(isset($_POST['submit'])) $forum_n = $_POST['name']; $bug_des = $_POST['bug_des']; $screen1 = $_POST['screen1']; $screen2 = $_POST['screen2']; $screen3 = $_POST['screen3']; $bug_type = $_POST['bug_type']; $pri_lvl = $_POST['radio']; ?> <center><font size=5 color="white"> <?php function pr(){ echo $pri_lvl; } echo "Posted by: $forum_n <br />"; echo "Description: $bug_des <br />"; echo "Screenshots: $screen1 <br />"; echo "Priority: $pri_lvl <br />"; pr(); ?></font></center> </body></html> Everything works fine, but the function pr isn't working... It won't echo $pri_lvl. Why is that? What have I done wrong ? Link to comment https://forums.phpfreaks.com/topic/96539-function-problem/ Share on other sites More sharing options...
craygo Posted March 17, 2008 Share Posted March 17, 2008 the value is not being sent to the function try this function pr($value){ echo $value; } Now pass the value to the function pr($pri_lvl); So any value you put in the parenthesis will be echo'd out Ray Link to comment https://forums.phpfreaks.com/topic/96539-function-problem/#findComment-494041 Share on other sites More sharing options...
johnny44 Posted March 17, 2008 Share Posted March 17, 2008 Or if you want a function with no input, then use "global" to tell the function the value of $pri_lvl. The function doesn't know because it wasn't told. Initializing $pri_lvl earlier on in the script isn't enough. function pr(){ global $pri_lvl; echo $pri_lvl; } This will then do: pr(); "Global" picks up the value of $pri_lvl and tells the function what it is. Link to comment https://forums.phpfreaks.com/topic/96539-function-problem/#findComment-494087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.