ReferenceError因为单词

时间:2015-06-24 15:10:18

标签: javascript php mysql

我需要在数据库中写一个单词,我不能得到一个错误:ReferenceError: Patikrinta is not defined这是我的ajax脚本,它将数据发送到php文件。贝娄有PHP脚本,如果你需要它。无法在stackowerflow中找到解决方案。

$s .= "\n\t<td>";
$canEdit = getPermission('tasks', 'edit', $a['task_id']);
$canViewLog = getPermission('task_log', 'view', $a['task_id']);
$currentTasken=$a['task_id'];
$currentUser=$AppUI->user_id;
$currentPercent="5";
$currentDescription="Patikrinta";
if ($canEdit) {
    $s .= ("\n\t\t".'<a href="#">'
           . "\n\t\t\t".'<img src="./images/icons/tick.png" alt="' . $AppUI->_('Check') 
           . '" border="0" width="12" height="12" onclick="javascript:insertData('. $currentTasken .', '.$currentUser.', '.$currentPercent.', '.$currentDescription.')" />' . "\n\t\t</a>");
}
$s .= "\n\t</td>";
?>
<script type="text/javascript">

// Note that you should use `json_encode` to make sure the data is escaped properly.
var currentTasken = <?php echo json_encode($currentTasken=$a['task_id']); ?>;
var currentUser = <?php echo json_encode($currentUser=$AppUI->user_id); ?>;

function insertData(currentTasken, currentUser, currentPercent, currentDescription)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("POST","modules/tasks/datafile.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

    // Here, use the JS variables but, likewise, make sure they are escaped properly with `encodeURIComponent`
    xmlhttp.send("currentUser=" + encodeURIComponent(currentUser) + "&currentTasken=" + encodeURIComponent(currentTasken) + "&currentPercent=" + encodeURIComponent(currentPercent)+ "&currentDescription=" + encodeURIComponent(currentDescription));
}

</script>

这是我的php脚本:

<?php
$currentUser = isset($_POST['currentUser']) ? $_POST['currentUser'] : '';
$currentTasken = isset($_POST['currentTasken']) ? $_POST['currentTasken'] : '';
$currentPercent = isset($_POST['currentPercent']) ? $_POST['currentPercent'] : '';
$currentDescription = isset($_POST['currentDescription']) ? $_POST['currentDescription'] : '';
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    if(!$con)
        die('Could not connectzzz: ' . mysql_error());
    mysql_select_db("foxi" , $con) or die ("could not load the database" . mysql_error());

    $check = mysql_query("SELECT * FROM dotp_task_log");
    $numrows = mysql_num_rows($check);
    if($numrows >= 1)
    {
        //$pass = md5($pass);

        $ins = mysql_query("INSERT INTO dotp_task_log (task_log_creator, task_log_Task, task_log_description) VALUES ('$currentUser' , '$currentTasken', '$currentDescription')" ) ;

        if($ins)
        {
                $check = mysql_query("SELECT * FROM dotp_tasks");
                $numrows = mysql_num_rows($check);
                if($numrows > 1)
                {
                    //$pass = md5($pass);

                    $inss = mysql_query("UPDATE dotp_tasks SET task_percent_complete = '$currentPercent' WHERE task_id='$currentTasken'") ;

                    if($inss)
                    {
                        die("Succesfully added Percent!");
                    }
                    else
                    {
                        die("GERROR");
                    }

                }
                else
                {
                    die("Log already exists!");
                }
        }
        else
        {
            die("ERROR");
        }

    }
    else
    {
        die("Log already exists!");
    }


?>

1 个答案:

答案 0 :(得分:0)

您是否尝试在函数参数周围添加引号? JS正在寻找Patikrinta&#39; Patikrinta&#39;因为你没有在字符串周围添加引号。它应该更像这样:

javascript:insertData('. $currentTasken .', '.$currentUser.', '.$currentPercent.', \''.$currentDescription.'\')" />' . "\n\t\t</a>");

其他参数有效,因为它们作为数字传递,Javascript将它们解释为数字。这里的区别是$currentDescription的值Patikrinta不是数字,所以JS会查找一个名为的变量或对象。

作为旁注 - 如果可以的话,值得切换使用MySQLi。不推荐使用MySQL_*个函数。