PHP Applications
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Applications

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 12th, 2006, 04:12 PM
foosoo foosoo is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 foosoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help with an error in a testing script phptest (search_array)

hello all and thank you all so much ahead of time for any help.. I am using a old, unsupported testing/quiz script called phptest. My webhost is telling me since they switched me to the new servers they are getting errors in their php logs about 2gigs a day from my scipt.. Now.. I prob had the error on the old servers but they prob didnt log or didnt notice it..

Is it normal for webhosts to have logging on in php? I would say that they would have a lot of errors from all the domains...

ok so here is the error they sent me

[11-Aug-2006 19:08:08] PHP Warning: array_search(): Wrong datatype for
second argument in
/hsphere/local/home/jonathan/rescueexams.com/firetest/question.php on line
126
[11-Aug-2006 19:08:41] PHP Warning: array_search(): Wrong datatype for
second argument in
/hsphere/local/home/jonathan/rescueexams.com/firetest/question.php on line
126
[11-Aug-2006 19:08:57] PHP Warning: array_search(): Wrong datatype for
second argument in
/hsphere/local/home/jonathan/rescueexams.com/firetest/question.php on line
126

So I opened up question.php and here is lines 125-134

php Code:
Original - php Code
  1.        // figure out which question number we are on.
  2.         $question_number = array_search($question_id, $test_session->questions);
  3.         // we need to compare types using the '===' comparison operator because array_search() can return
  4.         // 0 for the index which evaluates to false using the normal '==' comparison operator
  5.         if ($question_number === FALSE) {
  6.             pt_exit('Fatal Error: unable to determine question number.');
  7.         }
  8.  
  9.         // output test title and additional notes
  10.         echo "<div class="form"><center><h2>{$test_session->info['description']}</h2></center>";


as you can see this is line 126
$question_number = array_search($question_id, $test_session->questions);


so do you need more info to diagnos the issue?
I dont seem to be having any issues as far as testing is concerned but who know for sure..

can this line safely be removed?

Any ideas?

I am migrating towards another testing script and I am looking at moodle right now any other suggestions for a feature rich script would be great.!

THANKS SOOO MUCH

ALSO.. here is the whole code in the file question.php
this is all the code from the file above called question.php with the line 126 problem

hope this helps and if anyone needs more please tell me.. it doesnt seem like anyone is helping me on this here but i hope it will turn around..

php Code:
Original - php Code
  1. <?php
  2. /**************************************************  ***************************
  3.     $Id: question.php,v 1.2 2002/10/17 17:26:44 djresonance Exp $
  4.     Copyright 2002 Brandon Tallent
  5.     This file is part of phpTest.
  6.     This program is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU General Public License
  8.     as published by the Free Software Foundation; either version 2
  9.     of the License, or (at your option) any later version.
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. **************************************************  ***************************/
  18.  
  19. function draw_sidebar()
  20. {
  21.     global $test_session, $PHP_SELF;
  22.     echo "<div class="menu">n";
  23.  
  24.     $count = 1;
  25.     foreach ($test_session->questions as $question_id) {
  26.         echo pt_make_href("$PHP_SELF?question_id=$question_id", $count++);
  27.     }
  28.  
  29.     echo "</div>n";
  30. }
  31.  
  32. function draw_question($question_id)
  33. {
  34.     global $db, $user, $strings, $question_number, $test_session;
  35.     // edit will hold the html to display the 'edit' icon if the user is an admin
  36.     $edit = '';
  37.     // pull all of the info about the question from the db into our $row object
  38.     $result = $db->query("SELECT * FROM questions WHERE question_id = $question_id");
  39.     $row = $db->fetch_object($result);
  40.  
  41.     // begin question
  42.     echo "<tr>n";
  43.     echo " <td bgcolor="" . pt_table_highlight(0) . "">n";
  44.  
  45.     $image = 'edit_light.png';
  46.     $style = 'even';
  47.  
  48.     // show the link to edit the question if user is an admin
  49.     if ($user->admin) {
  50.         $edit .= pt_make_href("edit_question.php?question_id=$question_id&question_type_id=$row->question_type_id", "<img src="images/$image" border="0">", $strings['TEST_EDIT_QUESTION']);
  51.     }
  52.     // create a question object based on the question_type_id
  53.     $question = pt_inst_qclass($row->question_type_id);
  54.     // draw the question
  55.  
  56.     if (isset($test_session->answers[$question_number])) {
  57.         $question->draw_test_question($question_id, $question_number + 1, $edit, $style, $test_session->answers[$question_number]);
  58.     } else {
  59.         $question->draw_test_question($question_id, $question_number + 1, $edit, $style);
  60.     }
  61.  
  62.     echo "  </td>n";
  63.     echo "</tr>n";
  64.     // end question
  65. }
  66.  
  67.     require_once('./include/h.inc.php');
  68.     pt_register('GET', 'question_id');
  69.     pt_register('POST', 'submit', 'questions', 'question_id', 'question_number', 'prev', 'next');
  70.     pt_register('SESSION', 'test_session');
  71.  
  72.     $question_count = count($test_session->questions) - 1;
  73.  
  74.     if (isset($next)) {
  75.  
  76.         foreach($questions as $question_id => $answer) {
  77.             list($test_session->answers[$question_number]) = pt_clean_vars($answer);
  78.         }
  79.  
  80.         $next_question_id = $test_session->questions[$question_number + 1];
  81.         pt_redirect("question.php?question_id=$next_question_id");
  82.     }
  83.  
  84.     if (isset($prev)) {
  85.  
  86.         foreach($questions as $question_id => $answer) {
  87.             list($test_session->answers[$question_number]) = pt_clean_vars($answer);
  88. //            $test_session->answers[$question_number] = $answer;
  89.         }
  90.  
  91.         $prev_question_id = $test_session->questions[$question_number - 1];
  92.         pt_redirect("question.php?question_id=$prev_question_id");
  93.     }
  94.  
  95.  
  96.     if (isset($submit)) {
  97.  
  98.         // make sure to update the answer into our test_session var
  99.         foreach($questions as $question_id => $answer) {
  100.             list($test_session->answers[$question_number]) = pt_clean_vars($answer);
  101.         }
  102.  
  103.         $count = 0;
  104.  
  105.         // now, we need to reconstruct the questions array in a format that
  106.         // $test->grade() will understand.  This is just using a little array trickery.
  107.         foreach ($test_session->questions as $question_id) {
  108.             $questions[$question_id] = $test_session->answers[$count++];
  109.         }
  110.  
  111.         // instantiate the test object so we can grade the test
  112.         $test = new cTest($test_session->test_id);
  113.  
  114.         $test->grade($questions);
  115.         pt_redirect("view_results.php?user_id=$user->user_id&feedback=" . urlencode($strings['TEST_SCORED']));
  116.     } else {
  117.         require_once('./include/header.inc.php');
  118.         // draw_sidebar();
  119.         // print_r($test_session);
  120.  
  121.         // figure out which question number we are on.
  122.         $question_number = array_search($question_id, $test_session->questions);
  123.         // we need to compare types using the '===' comparison operator because array_search() can return
  124.         // 0 for the index which evaluates to false using the normal '==' comparison operator
  125.         if ($question_number === FALSE) {
  126.             pt_exit('Fatal Error: unable to determine question number.');
  127.         }
  128.  
  129.         // output test title and additional notes
  130.         echo "<div class="form"><center><h2>{$test_session->info['description']}</h2></center>";
  131.  
  132.         if ($test_session->info['notes']) {
  133.             echo "<hr noshade="noshade" size="1" />n";
  134.             echo $test_session->info['notes'];
  135.         }
  136.  
  137.         echo "</div>n";
  138.         echo "<form method="post" name="test" action="$PHP_SELF">n";
  139.         echo "<div class="test">n";
  140.         echo "<table width="100%" cellspacing="0" cellpadding="8">n";
  141.  
  142.         draw_question($question_id);
  143.  
  144.         echo "</table>n";
  145.         echo "</div>n";
  146.         echo "<input type="hidden" name="question_number" value="$question_number" />n";
  147.         echo "<input type="hidden" name="question_id" value="$question_id" />n";
  148.  
  149.         // show the previous button unless we're on the first question
  150.         if ($question_id != $test_session->questions[0]) {
  151.             echo "<input type="submit" name="prev" value="<< {$strings['TEST_PREVIOUS_QUESTION']}" />n";
  152.         }
  153.  
  154.         // show the next button unless we're on the last question
  155.         if ($question_id != $test_session->questions[$question_count]) {
  156.             echo "<input type="submit" name="next" value="{$strings['TEST_NEXT_QUESTION']} >>" />n";
  157.         }
  158.  
  159.         echo "<input type="submit"  name="submit" value="{$strings['TEST_SUBMIT']}" />n";
  160.         echo "</form>n";
  161.  
  162.         require_once('./include/footer.inc.php');
  163.     }
  164. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Applications > help with an error in a testing script phptest (search_array)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek