调用另一个页面上的php函数不起作用Uncaught ReferenceError:未定义测试



我正在尝试调用另一个页面中的函数,结果得到:Uncaught ReferenceError:测试未定义

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

代码块:

索引.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语句。一旦我点击单选按钮调用函数,我就会得到错误。请原谅我还在学习的代码。

您可以这样做:

onchange='test(this.value);'

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

它将$_POST['postddata']发送到某个位置。php

您的test函数是php,如果您正在执行onchange调用,它将尝试在Javascript中找到一个名为test的函数。如果你想在不刷新页面的情况下通过onclick事件调用test函数,你正在寻找一个名为ajax的东西。关于ajax的更多信息可以在这里找到:http://www.w3schools.com/php/php_ajax_php.asp

相关内容

最新更新