Jump to content

Function problem.


Braveheartt

Recommended Posts

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  :P?

 

Link to comment
https://forums.phpfreaks.com/topic/96539-function-problem/
Share on other sites

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

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.