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';
}

?>

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.

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

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';
}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.