User Defined Functions

Typical User Defined Functions

<?php

function log_data($user, &$data) {

    if($mysqli->ping()) {

        $mysqli->query("INSERT INTO userdata VALUES ('".uniqid()."', '".$mysqli->real_escape_string($user)."', '".$mysqli->real_escape_string($data)."')");

    } else {

        echo 'MySQL server has gone away. Kindly create the connection again';

    }

}

?>

Pass-by-reference

<?php log_data($_SERVER['PHP_AUTH_USER'], $data); ?>

Default values

<?php
    function head( $title="Default HTML Title" ) {
?>
        <!Doctype html>
            <head>
                <title> <?php echo $title; ?> </TITLE>
            </head>
            <body>
<?php
    }
    

// Calling the head() Function without any paramter.

    head();

// Calling the head() function with parameter
// Remove below comment 


//    head("This is my Another HTML title");
?>

                <p> This is Body Content </p>

            </body>
        </htmnl>

Loading ...

Related Results :

  1. User Defined Functions
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author