Php 如何调用函数以使用它来缩短代码

Php 如何调用函数以使用它来缩短代码,php,html,function,Php,Html,Function,在脚本的chk_Btn_Sub()中如何使用此函数,我哪里出错了 <?php //start my session session_start(); //calling the function chk_Btn_Sub(); ?> //displays my form <form method="post" action="captcha.php"> <table border="0" cellspacing="3" cellpadding="3">

在脚本的chk_Btn_Sub()中如何使用此函数,我哪里出错了

<?php
//start my session
session_start();
//calling the function
chk_Btn_Sub();
?>
//displays my form
<form method="post" action="captcha.php">
    <table border="0" cellspacing="3" cellpadding="3">
        <tr><td>Type The Letters You See Below Into the Box</td></tr>
        <tr><td align="center"><img src="image.php"></td></tr>
        <tr><td align="center"><input type="text" name="image" value="">
        //check if the $error = true
        <?php if (isset($error)): ?>
            <div style="color:red;">error</div>
        <?php else: ?>
            <?php if (isset($success)):?>
                <div style="color:green;">success</div>
            <?php endif ?>
        <?php endif ?>
        </td></tr>
        <tr><td align="center"><input type="submit" name="submit" value="Check CAPTCHA">     </td></tr>
    </table>
</form>

//显示我的表单
将下面看到的字母输入框中
//检查$error是否为true
错误
成功
这是我要创建的函数,在页面顶部的session_start()函数下调用


您正在正确调用函数,但在使用函数之前,需要记住
包含该函数所在的文件。比如说

<?php
//start my session
session_start();
//include the file
include 'path/to/file.php';
//calling the function
chk_Btn_Sub();
?>


您是否
包含函数所在的.php文件?不回答您的问题,但
//检查$error=true
它不检查
$error
是否正确true@DickieBoy这是因为我在函数中检查$error。我试图缩短我的代码,更好地理解php@hermann你认为我哪里做错了?@code我刚纠正了你标题中的一个拼写错误。除此之外没什么错。那没什么用bro@code你有错误报告吗?您是否有任何错误?如果我在同一个文件中使用该函数,并将其放在代码底部的下面,那么我仍然可以使用该函数作为检查,然后再将我的函数移动到新文件以包含在主脚本的顶部是的,我将其设置为错误报告(E_ALL);ini_设置(“显示错误”,真);函数chk_Btn_Sub($error,$success)
<?php
//start my session
session_start();
//include the file
include 'path/to/file.php';
//calling the function
chk_Btn_Sub();
?>