2015-06-22 20:58
浏览 52

在另一个页面上调用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:


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;">
                    <td><b>Gross Commission Amount</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>
        // Print each file
        while ($row = mysql_fetch_assoc($result)) {
            echo "
                    <td>$" . number_format($row['gross_commission_amount'], 2) . "</td>
                    <td>{$row['FName']} {$row['LName']}</td>
if($delemail == $row) {
                echo "<td><form><input value={$row['email_address']} type='radio' name='selected_already' checked='checked'></input></form>/td>";

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>";


function test(){

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

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

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:



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

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

    打赏 评论
  • dqx24298 2015-06-22 21:02

    Your test function is php, if you're doing an onchange call it will try and find a function called test in Javascript. If you want to call the test function trough an onclick event without refreshing the page you're looking for something called ajax more info on ajax can be found here :

    打赏 评论

相关推荐 更多相似问题