Jump to content

xxreenaxx1

Members
  • Posts

    167
  • Joined

  • Last visited

    Never

Everything posted by xxreenaxx1

  1. SELECT p.orderid, p.updated, p.origsalesman, p.salesman, p.status, p.profit, p.product, p.orderdate, o.price FROM printersales p, printers pr, orderdetail o WHERE o.productid = pr.productid AND p.orderid = o.orderid AND p.updated > '2011-08-5 00:00:01' This is my code and when I do this query without it gives me 29 results but if I do the query shown above it gives me 24 result so I am missing few field and not sure why. Any idea why its doing this? Do I have an error on my code??
  2. I am printing question id and corect answers and incorrect one. Example: Questionid =8 Incorrect Incorrect Incorrect Correct Correct Incorrect This will be repeated for other question id. Now I would like to count total answers. In my example it will be 6. I would like to count the correct one so that will be 2. And print 2 as outcome. So far I have $sqlll=questionid(); while($infoo = mysql_fetch_array( $sqlll)) { echo "<hr><br><strong>{$infoo['Que_ID']}</strong><br />\n"; $_Session1=$infoo['Que_ID']; $que=question($_Session1); while($infooo = mysql_fetch_array( $que)) { $answer1 = $infooo['Que_Answer1'] == $infooo['Ans_Answer1']; $answer2 = $infooo['Que_Answer2'] == $infooo['Ans_Answer2']; $answer3 = $infooo['Que_Answer3'] == $infooo['Ans_Answer3']; $answer4 = $infooo['Que_Answer4'] == $infooo['Ans_Answer4']; if ( $answer1 && $answer2 && $answer3 && $answer4) { echo ('<b><p style="color: green; text-align: left"> Correct </p></b>'); $scoree = $scoree + 1; } else { echo ('<br><b><p style="color: red; text-align: left"> Incorrect </p></b></br>'); $intt= $intt +1; } }
  3. My connection wasnt correct. That was my error Thanks
  4. I have tried to run my code and it works. I am not getting any error message but when I checked my database nothing was added. <?php session_start(); include '../Database/connection.php'; if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } $filename = $_FILES["file"]["tmp_name"]; $fd = fopen ($filename, "r"); $data = fread ($fd,filesize ($filename)); fclose ($fd); $delimiter = "\n"; $output = explode($delimiter, $data); foreach($output as $var) { $tmp = explode(".", $var); $question = $tmp[0]; $choice1 = $tmp[1]; $choice2 = $tmp[2]; $choice3 = $tmp[3]; $choice4 = $tmp[4]; $answer1 = $tmp[5]; $answer2 = $tmp[6]; $answer3 = $tmp[7]; $answer4 = $tmp[8]; $sql = "INSERT INTO question SET Que_Question='$question', Que_Choice1='$choice1', Que_Choice2='$choice2', Que_Choice3='$choice3', Que_Choice4='$choice4', Que_Answer1='$answer1', Que_Answer2='$answer2', Que_Answer3='$answer3', Que_Answer4='$answer4', Tes_ID='$_SESSION[Tes_ID]'"; mysql_query($sql); } ?> My text file holds
  5. I dont know how implement that?? :S
  6. oh.. I want to check if the user has already taken a question. This is the reason why I am compairing a.Que_ID = q.Que_ID. So if the person has taken the exam, this will not be displayed.
  7. I am trying to run this query on a webpage but I am getting an error. So I tested this on mysql and this is giving me error as well. IF EXISTS (SELECT * FROM user u, subject s, test t, question q, answer a WHERE u.Use_ID = 1 AND t.Sub_ID = 1 AND s.Sub_ID = t.Sub_ID AND q.Que_ID = a.Que_ID) am I doing anything wrong.
  8. Nope. I tired few other ways as well. Nothing works. This is the error message I am getting I am using function for this method. And on line 3 I have function comple($Test_ID){
  9. How can you make these two delete function as one. DELETE FROM test WHERE Tes_ID= 11; DELETE FROM question WHERE Tes_ID=11;
  10. I am trying to use delete function but not sure if I can have something like this. If not can someone suggest something ("DELETE FROM answer (Ans_Answer1, Ans_Answer2, Ans_Answer3, Ans_Answer4, Que_ID, Use_ID) VALUES ('1', '1', '0', '0', '1', '1')")
  11. I am writing a program which checks the results for a student. If the results are same as the ones inside the table, then correct message is printed. If the results are not the same then the right answer should be printed as well as wrong message and the answer the user selected. I am using checkbox to let the user choose the answers and this is saved on to the database. I need to retrieve this and compare this with the original table. my tables are Answer: ,Ans_ID,Ans_Answer1, Ans_Answer2, Ans_Answer3, Ans_Answer4,Que_ID Question:Que_ID, Que_Answer1, Que_Answer2, Que_Answer3, Que_Answer4 Answer table is what the user enters and the question table is the one with the correct answer. SELECT Ans_ID, IF(answer.Ans_Answer1 = question.Que_Answer1 AND answer.Ans_Answer1 = question.Que_Answer1 AND answer.Ans_Answer1 = question.Que_Answer1 AND answer.Ans_Answer1 = question.Que_Answer1, "Correct","Wrong") AS result FROM answer LEFT JOIN question ON answer_id = question_id can someone give me ideas, not asking for you to write the code for me. just help me out as I am stuckk
  12. I have a code that works but it wont add the data to my database. It says the data has been added but the actual data is not actually added. I have checked through this code to see any errors but I cant find any. Can someone help me $sqll= takeanexam($_SESSION['username1'], $_SESSION['ssubject'], $_SESSION['smodule']); // mysql_data_seek(sqll, 0); while($info = mysql_fetch_array( $sqll )) { $questionId = $info['Que_ID']; $choice = array(); for ($i =1; $i < 5; $i++) { if (empty($_POST['choice'][$questionId][$i])) { $choice[$i] = 0; } else { $choice[$i] = 1; } } $username= $_SESSION['username1']; mysql_query("INSERT INTO answer (Ans_Answer1, Ans_Answer2, Ans_Answer3, Ans_Answer4, Que_ID, Use_ID) VALUES ({$choice[1]}, {$choice[2]}, {$choice[3]}, {$choice[4]}, $questionId, $username)"); }
  13. Nope, its not sorted. This is what I get when I print
  14. I got it sorted. Thanks anyways
  15. I have foreach method. This displays the choices that are selected and the value inside them as 1. The method is shown below. I am printing these with the name(choice1, choice2, choice3, choic4) and the value. If there is a value then it prints 1. Now my problem is I want to INSERT them into my database. if it prints choice1, choice2 then value 1 must be entered into choice1 and choice2 inside the database. I am not sure how to do this. can someone help me. foreach ($_POST["choice"] as $question => $answer) { if($answer == NULL) { $val=0; } else{ $val = 1; } echo "choice id: $question. value: $val <br />";
  16. I am stuck on inserting the data into mysql via php. Its a foreach method and I am just stuck include '../Database/take_an_exam.php'; $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; for ($i =1; $i < 5; $i++) { echo "<input type=\"checkbox\" name=\"choice[{$info['Que_ID']}.$i][]\" />{$info['Que_Choice'.$i]}<br />\n"; $intnumber++; } } ?> <input type="submit" value="submit" name="submit"> This is my form that can output the Question and its choices. I am echoing this on to the next page, the code is shown below <?PHP session_start(); $name= $_SESSION['username1']; echo "User ID: $name <br/>"; $gender = $_POST["choice"]; $que_ID = $_POST["Que_ID"]; foreach ($gender as $key => $array) { if($array) { $val=1; } ///echo "Question ID and the choice ID:$key. Value is:.$val <br />\n"; $well = array(floor($key), substr(strstr($key, '.'), 1)); //$well = array(floor($key), $key - floor($key)); echo "Question ID: $well[0], "; echo "Choice: $well[1]. value: $val<br/>"; } //}break; ?> Now, instead of echoing. I just want to add this to mysql. The layout of my sql is Que_ID, Ans_Choice1, Ans_Choice2, Ans_Choice3, Ans_Choice4, Use_ID When I echo my php my outcome is
  17. when I type something in my form like Tes_Name= "blah blah", then its giving me that error.. and when i type in Tes_Name = Tes_Name and Tes_Description = Tes_Description, my sessions are added to the table but test name and test description field are empty
  18. My form <body> <h3>Test</h3> <table border="0"> <form method="POST" action="Test_descrip_action.php"> <tr><td>Tes_Name</td><td>:</td><td><input type="text" name="Tes_Name" size="20"></td></tr> <tr><td>Tes_Description</td><td>:</td><td><input type="text" name="Tes_Description" size="20"></td></tr> <tr><td> </td><td> </td><td><input type="submit" value="Submit"></td></tr> </form> </table> </body> </html> I am posting this to the blow code page $value = modulesql($_POST['Tes_Name'], $_POST['Tes_Description'], $_SESSION['ID'], $_SESSION['myselect']); header("location:Add_Question_Form.php"); My function code function modulesql($TestName, $TestDescription, $UserID, $SubjID){ $con = OpenConnection(); $module = mysql_query("INSERT INTO test (Tes_Name, Tes_Description , `Use_ID`, `Sub_ID`) VALUES ($TestName, $TestDescription, $UserID, $SubjID)") or die('Cannot Execute:'. mysql_error()); $_SESSION['Tes_ID'] = mysql_insert_id(); CloseConnection($con); return $module; Thats all I am working with. And the connection code. Which works.
  19. I am getting an error message That Column is Tes_Name.
  20. Thank you for the information. My data was adding before I did function. Now it wont add to my database. The below code is where the form should be adding to the database. session_start(); include '../Database/connection.php'; include '../Database/test_form_sql.php'; $val= OpenConnection(); mysql_select_db("examination"); $postVar1 = mysql_real_escape_string(trim($_POST['Tes_Name'])); $postVar2 = mysql_real_escape_string(trim($_POST['Tes_Description'])); $SessionVar1 = mysql_real_escape_string(trim($_SESSION['ID'])); $SessionVar2 = mysql_real_escape_string(trim($_SESSION['myselect'])); $value = modulesql($postVar1, $postVar2, $SessionVar1, $SessionVar2); header("location:Add_Question_Form.php"); ?> The function method is below. function modulesql($Tes_Name, $Tes_Description, $Use_ID, $Sub_ID){ $con = OpenConnection(); mysql_select_db("examination", $con); $module = ("INSERT INTO test (`Tes_Name`, `Tes_Description`, `Use_ID`, `Sub_ID`) VALUES ($Tes_Name, $Tes_Description, $Use_ID, $Sub_ID)") or die('Cannot Execute:'. mysql_error()); $_SESSION['Tes_ID'] = mysql_insert_id(); CloseConnection($con); return $module; When I type something in the form and go through the action code, it does redirect to header("location:Add_Question_Form.php");, but nothing is added to the database.
  21. I am using function to insert into database. But the primary key is automatic and I used to retrieve this. But now that I use function method. I am not sure how to retrieve the primary key on to the next page. $value = modulesql($postVar1, $postVar2, $SessionVar1, $SessionVar2); $_SESSION['Tes_ID'] = mysql_insert_id(); echo $value, $_SESSION['Tes_ID']; <?php function modulesql($Tes_Name, $Tes_Description, $Use_ID, $Sub_ID){ $con = OpenConnection(); mysql_select_db("examination", $con); $module = ("INSERT INTO test (`Tes_Name`, `Tes_Description`, `Use_ID`, `Sub_ID`) VALUES ($Tes_Name, $Tes_Description, $Use_ID, $Sub_ID)") or die('Cannot Execute:'. mysql_error()); CloseConnection($con); return $module; } ?> Have I lost you with my question??
×
×
  • 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.