0
i m traying this simples code but nothing is displayed what type of problem showld be.


<?php
function yourname($name)
{
echo "Your name is" .$name;
}
yourname("andi");

?>
another code

<?php

$age= 18;

if ($age>=21)
{
echo 'alan';

}else{
echo 'bob';
}

?>
4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by Bachu
0

First you should provide a bit of detail on how you are trying to run it. To run PHP code, you need a server. Do you have a local test server (like WAMP) that you are using. If not, there are many available that you can download and install.

0

Typically functions will either be in a seperate file, or at the bottom of the php file:

<?php

yourname("Shamp");


function yourname($name){
    echo "Your Name is " .$name ;
}
?>

This works fine. Because you are calling a function with the assigned data. PHP then continues to look through the code, locates the function and triggers.

This also works:

$age = 18;

if($age >= 21){
    echo "Alan";
}
else{
    echo "Bob";
}

Only difference is the spacing around the math, and " instead of ' around the names

Edited by Squidge

0

You can't run php file like html file.You need test server(WAMP/XAMP) for testing php code.

<?php
function yourname($name)
{
    echo "Your name is " .$name;
}

yourname("andi");

$age= 18;

if ($age>=21)
{
    echo ' alan';
}
else{
    echo ' bob';
}

?>

Edited by Bachu

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.