0

这是我的主要 php 文件。我只包括相关代码:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-AU">

 <head>
 <title>OSTA - Take Test</title>

 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />

 <link href="css.css" rel="stylesheet" type="text/css" />  

 <script language="javascript" type="text/javascript" src="editarea/edit_area/edit_area_full.js"></script>

</head>

<body>

<div class="wrapper">
<div class="header">
<h1> OSTA - Take Test</h1>
</div><!-- end header -->

<div class="nav">
<ul>
<li>Hello <?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF- 8');    ?></li>
<li><a href="s_assignments.php">Assignments</a></li>
<li><a href="s_edit_account.php">Edit Account</a></li>
<li><a href="s_logout.php">Logout</a></li>
</ul>
</div><!-- end nav -->

<div class="content">   
<?php   
echo "<form id='code' action='take_test.php' method='post'>";
$con=mysqli_connect($host,$username,$password,$dbname);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


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

$aa = $_POST['source'];
    $query = "INSERT INTO student_test(status,user_name,aaid,qqid,answer,submit_time)
VALUES('1','{$_SESSION['user']     ['username']}','{$_POST['edit']}','{$_POST['qid']}','{$aa}',NOW())";
  $rest5=mysqli_query($con,$query);

$qry="SELECT qid FROM questions where aid={$_POST['edit']}
ORDER BY qid DESC
LIMIT 1";
$restfinal=mysqli_query($con,$qry);
$rowfinal = mysqli_fetch_array($restfinal);
$qidfinal = $rowfinal['qid'];
if ($qidfinal==$_POST['qid'])
{   
echo "Test Submitted Successfully.";
sleep( 3 );
header("Location: s_assignments.php");
echo "Test Submitted Successfully.";
}
}
echo "<input type='hidden' value='$a' name='a'>";

 echo "<td>"."<input type='submit' class='button' name='compile' id='compile'   value='Compile Code'>"."</td>";
 echo "<td>"."<input type ='submit' class='button' name ='next' value='Next   Question'>"."</td>";

 echo"</form>";

?>
<div id="response">
    <div class="meta"></div>
    <div class="output"></div>
</div>
</div><!-- end content -->

<div class="footer">
 <p>designed by  |  &copy;  </p>
 </div><!-- end footer -->
 </div><!-- end wrapper -->
  <script language="javascript" type="text/javascript">
  editAreaLoader.init({
  id : "source"       // textarea id
  ,syntax: "css"          // syntax to be uses for highgliting
  ,start_highlight: true      // to display with highlight mode on start-up
 });
</script>

<script type="text/javascript" src="jquery.min.js"></script>
<script src="script.js"></script>     
 </body>
 </html>

上面的代码负责编译用户在文本区域中通过单击编译按钮输入的代码,也可以通过单击下一个问题按钮移动到下一个问题。是的,这是 php 中的测验程序。当用户单击编译按钮时 script.js 文件响应并在 div id="response" 标记中给出输出。

这是 script.js 代码:-

jQuery(document).ready(function($) {
var buttonpressed;

$('.button').click(function() {
  buttonpressed = $(this).attr('name');
});

$('#code').submit(function() {
  //alert('Button Pressed is:' + buttonpressed);
  if(buttonpressed=="compile"){
    buttonpressed='';
    var data = $(this).serialize();
    var source = $('textarea#source').val();

    if( source == '' ) {
        alert( 'No source code provided');
        return false;
    }
    $(this).append('<div class="loading">Processing...</div>');
    $.ajax({
        type: 'post',
        url: 'process.php',
        dataType: 'json',
        data: data + '&process=1',
        cache: false,
        success: function(response){
            $('.loading').remove();
            $('.cmpinfo').remove();
            $('#response').show();
            //alert(response);
            console.log(response.raw);
            if( response.status == 'success' ) {
                $('.meta').text( response.meta );
                $('.output').html('<strong>Output</strong>: <br><br><pre>' + response.output + '</pre>');
                if( response.cmpinfo ) {
                    $('.cmpinfo').remove();
                    $('.meta').after('<div class="cmpinfo"></div>');
                    $('.cmpinfo').html('<strong>Compiler Info: </strong> <br><br>' + response.cmpinfo );
                }
            } else {
                //$('.output').html('<pre>' + response + '</pre>');
                alert( response.output );
            }
        }
    });
 return false;
 }
 else {
     return true;
 }
   });
 });// jquery ends

问题是当我点击编译按钮时它显示一个未定义的错误!

4

0 回答 0