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
Share on other sites

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