在另一个页面上调用php函数不工作Uncaught ReferenceError:test未定义

时间:2015-06-22 20:58:34

标签: php function include require

我正在尝试在另一个页面中调用一个函数并获取:未捕获的ReferenceError:未定义测试

两个页面是index.php和functions.php

代码块:

的index.php

if($result) {
    // Make sure there are some files in there
    if($result == '') {
        echo '<h1>There are no files in the database</h1>';
    }
    else {

require './functions.php';
        // Print the top of a table
        echo '<table class="table-survey" style="margin-left: 50px; width: 1400px;">
                <th>
                <tr>
                    <td><b>CSSID</b></td>
                    <td><b>GROUP</b></td>
                    <td><b>Class</b></td>
                    <td><b>Gross Commission Amount</b></td>
                    <td><b>Name</b></td>
                    <td><b>Email Address</b></td>
                    <td><b>Email Received</b></td>
                    <td><b>Email Sent</b></td>
                    <td><b>Notes from December</b></td>
                    <td><b>Not Used For Business</td>
                </tr>
                </th>';
        // Print each file
        while ($row = mysql_fetch_assoc($result)) {
            echo "
                <tr>
                    <td>{$row['cssid']}</td>
                    <td>{$row['grp']}</td>
                    <td>{$row['css_class']}</td>
                    <td>$" . number_format($row['gross_commission_amount'], 2) . "</td>
                    <td>{$row['FName']} {$row['LName']}</td>
                    <td>{$row['email_address']}</td>
                    <td>{$row['email_received']}</td>
                    <td>{$row['email_sent']}</td>
                    <td>{$row['additional_notes']}</td>";
if($delemail == $row) {
                echo "<td><form><input value={$row['email_address']} type='radio' name='selected_already' checked='checked'></input></form>/td>";
}
else{

echo "<td><form method='post' action='functions.php'><input value={$row['email_address']} type='radio' name='optradio' onchange='test(this.value);'></input></form></td>";

}
              echo "</tr>";

的functions.php

function test(){

if (!$link = mysql_connect('localhost', 'dummydata', 'dummydata')) {
    echo 'Could not connect to mysql';
    exit;
}

if (!mysql_select_db('test_table', $link)) {
    echo 'Could not select database';
    exit;
}


if (isset($_POST['optradio'])) {

$sql = "update email_data set additional_notes_new = case when additional_notes_new is null then 'NOT USED FOR BUSINESS' else concat(additional_notes_new, 'NOT USED FOR BUSINESS') END WHERE email_address = '$delemail' and additional_notes_new NOT LIKE '%NOT USED FOR BUSINESS%'";
$result = mysql_query($sql,$link);



}
return false;

};

所有POST和其他数据都在工作,包括粘贴代码之前的SQL语句。只要单击单选按钮调用该函数,我就会收到错误。请原谅我仍在学习的代码。

2 个答案:

答案 0 :(得分:1)

你可以这样做:

onchange='test(this.value);'

  onClick='$.post("somewhere.php",{posteddata:$(this).val()},function(){ })'

将$ _POST [&#39; posteddata&#39;]发送到somewhere.php

答案 1 :(得分:0)

您的test函数是php,如果您正在进行onchange调用,它会尝试在Javascript中找到一个名为test的函数。如果您想通过onclick事件调用test功能而不刷新页面,那么您需要查找名为ajax的内容ajax更多信息可在此处找到:{{3 }}