Jump to content

ximenao

New Members
  • Posts

    5
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ximenao's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello First of all I hope I have my question in the correct forum. I really need help with this problem! I'm sorry if the the solution is rather simple but I'm still kinda new to all this. I'm coding an online quiz for a client. The person must enter the correct answers into the input textboxes coded below: <li><input type="text" name="uno" size="25" maxlength="25" align="baseline" /><br /><br /></li> <li><input type="text" name="dos" size="25" maxlength="25" align="baseline" /><br /><br /></li> <li><input type="text" name="tres" size="25" maxlength="25" align="baseline" /><br /><br /></li> Once they submit the answers they are sent to the processing script shown below: <?php $uno = $_POST['uno']; $dos = $_POST['dos']; $tres = $_POST['tres']; $query="SELECT MATCH (q1) AGAINST ('$uno' IN BOOLEAN MODE) as ans1, MATCH (q2) AGAINST ('$dos' IN BOOLEAN MODE) as ans2, MATCH (q3) AGAINST ('$tres' IN BOOLEAN MODE) as ans3, FROM db_4_test"; $data=@mysql_query($query) or die(mysql_error()); echo "<p align=\"justify\">2. In the passage you have just read there are seven Spanish Speaking countries. List them in the spaces provided.</p>"; if($data["ans1"]!='0' && $data["ans1"]!='') { $a = 1; echo "<p><font color=\"#7E4B01\" size=\"+1\">\"<b>$uno</b> is correct!\"</font></p>"; } else { $a = 0; echo "<p><font color=\"#F00\" size=\"+1\">\"<b>$uno</b> is NOT a Spanish Speaking country found in the passage you have just read!</font></p>"; } if($data["ans2"]!='0' && $data["ans2"]!='') { $b = 1; echo "<p><font color=\"#7E4B01\" size=\"+1\">\"<b>$dos</b> is correct!\"</font></p>"; } else { $b = 0; echo "<p><font color=\"#F00\" size=\"+1\">\"<b>$dos</b> is NOT a Spanish Speaking country found in the passage you have just read!</font></p>"; } if($data["ans3"]!='0' && $data["ans3"]!='') { $c = 1; echo "<p><font color=\"#7E4B01\" size=\"+1\">\"<b>$tres</b> is correct!\"</font></p>"; } else { $c = 0; echo "<p><font color=\"#F00\" size=\"+1\">\"<b>$tres</b> is NOT a Spanish Speaking country found in the passage you have just read!</font></p>"; } $ex1sum = $a + $b + $c; $ex1percent = ($ex1sum/3)*100; echo "<p>You scored <b>$ex1sum</b> out of 13 total marks in Exercise IV.</p>"; if ($ex1percent >= 0 && $ex1percent <= 50) echo "<p><img src=\"images/exam_sorry_01.jpg\" width=\"287\" height=\"25\" alt=\"\" border=\"0\"><a href=\"quiz.php\"><img src=\"images/exam_sorry_02.jpg\" width=\"63\" height=\"25\" alt=\"\" border=\"0\"></a></p>"; if ($ex1percent >= 51 && $ex1percent <= 84) echo "<p><img src=\"images/exam_tryagain_01.jpg\" width=\"210\" height=\"25\" alt=\"\" border=\"0\"><a href=\"quiz.php\"><img src=\"images/exam_tryagain_02.jpg\" width=\"68\" height=\"25\" alt=\"\" border=\"0\"></a></p>"; if ($ex1percent >= 85 && $ex1percent <= 100) echo "<p><img src=\"images/exam_muybueno.jpg\" width=\"80\" height=\"25\" alt=\"\" border=\"0\"></p>"; ?> The script is a fulltext search which searches a series of columns in a database table and is supposed to find the correct answer. For example if the student enters "Cuba" it is supposed to return the answer as correct in other words display "Cuba is correct!". If the person enters say England it is supposed print "England is NOT a Spanish Speaking country found in the passage you have just read!" However no matter what the answer is it always gives the answer wrong even if it is present in the database. If I use just one argument (e.g.: if($data["ans1"]!='0' ) ) it gives every answer correct even it is not in database. Can someone please help me? Is there anything wrong with this script that I am missing? Thanks in advance ximenao
  2. Once again thanks for responding fenway... Yeh I dropped the initial index, the one with the multiple fields. Right now every field is indexed individually and it still doesn't work... Time is running out, I'm thinking of approaching it from a completely different angle but how I don't know as yet.
  3. Thanks for responding Fenway. Below is the MySQL code for the table CREATE TABLE formone_ex1_secthreesr ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `q1` TEXT( 75 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `q2` TEXT( 75 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `q3` TEXT( 75 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `q4` TEXT( 75 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , `q5` TEXT( 75 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ) And here is the code I used to modify each field to a fulltext index: ALTER TABLE formone_ex1_secthreesr ADD FULLTEXT(q1) Before I used this code ALTER TABLE formone_ex1_secthreesr ADD FULLTEXT q1 ( `q1` , `q2` , `q3` , `q4` , `q5` ) But that didn't work either.
  4. As an additional note, let me add that the MySQL version is 5.0
  5. Hello, I am making an online exam with textboxes. If the user enters an answer with the correct keyword or keywords, then he will be told "You are correct!" and of course "You are wrong" if the opposite is true... To do this I am using a fulltext search with a mysql database table with three fields (q1, q2, q3) with the text format and one id field as the primary key as tinyint set to auto increment. I used the following code: ALTER TABLE formone_ex1_secthreesr ADD FULLTEXT(q1,q2,q3,q4,q5); to create a fulltext index. I use phpmy admin which tells me that a fulltext index exists. It was recommended to me to use the following code: $query="SELECT MATCH (q1) AGAINST ('$uno' IN BOOLEAN MODE) as ans1, MATCH (q2) AGAINST ('$dos' IN BOOLEAN MODE) as ans2, MATCH (q3) AGAINST ('$tres' IN BOOLEAN MODE) as ans3 FROM formone_ex1_secthreesr"; $data=mysql_query($query) or die(mysql_error()); mysql_close(); if($data["ans1"]!='0') { echo "<p><font color=\"#7E4B01\" size=\"+1\"><b> $uno</b></font> is correct!</p>"; } else { echo "<p>Sorry,<font color=\"#FF0000\" size=\"+1\"><b> $uno</b></font> is wrong! The correct answer is <font color=\"#7E4B01\" size=\"+1\">\"<b>Yo me llamo John Smith</b>.\"</font></p>"; } if($data["ans2"]!='0') { echo "<p><font color=\"#7E4B01\" size=\"+1\"><b> $dos</b></font> is correct!</p>"; } else { echo "<p>Sorry,<font color=\"#FF0000\" size=\"+1\"><b> $dos</b></font> is wrong! The correct answer is <font color=\"#7E4B01\" size=\"+1\">\"<b>¿Qué hora es?</b>\"</font></p>"; } if($data["ans3"]!='0') { echo "<p><font color=\"#7E4B01\" size=\"+1\"><b> $tres</b></font> is correct!</p>"; } else { echo "<p>Sorry,<font color=\"#FF0000\" size=\"+1\"><b> $tres</b></font> is wrong! The correct answer is <font color=\"#7E4B01\" size=\"+1\">\"<b>¿Qué fecha es?</b>\"</font></p>"; } However, even if I enter an incorrect keyword, not contained within the database, it is returned as correct. Interestingly I tried removing "IN BOOLEAN MODE" and I get a error saying "Can't find FULLTEXT index matching the column list query:" Can anyone help me fix this please?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.