dongyan1974 2015-06-22 20:58
浏览 57
已采纳

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

I am trying to call a function in another page and getting : Uncaught ReferenceError: test is not defined

Two pages are index.php and functions.php

Code Blocks:

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;

};

All of the POST and other data is working including the SQL statements before the pasted code. As soon as I click the radio button to call the function I get the error. Please excuse the code I am still learning.

  • 写回答

2条回答 默认 最新

  • doumengmian1180 2015-06-22 21:25
    关注

    you can do this:

    onchange='test(this.value);'
    

    to

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

    its will $_POST['posteddata'] to somewhere.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧