Jump to content

Andrew R

Members
  • Posts

    158
  • Joined

  • Last visited

    Never

Everything posted by Andrew R

  1. In an sql query above the script. $query_entrytestdata = "SELECT * FROM entrypendingtest where id = '$testid'"; $entrytestdata = mysql_query($query_entrytestdata, $conn_abrv) or die(mysql_error()); $row_entrytestdata = mysql_fetch_assoc($entrytestdata); $totalRows_entrytestdata = mysql_num_rows($entrytestdata); $name = $row_entrytestdata['name']; I think the error has something to do with the issues between the old and new php versions as this exact script was working on a older php version. Thanks
  2. <?php $db = mysql_connect("server", "user", "pass"); mysql_select_db("database",$db); if ($useraction != 'checkit') { if($row_entrytestdata['taken'] == "No") { //Security start $updatedtest = "UPDATE entrypendingtest SET taken = 'Yes' where id = '$testid'"; $resultupdatedtest = mysql_query($updatedtest); $answer = array(); $question = array(); $qnum = array(); $orgid = array(); $i = 0; $query = "SELECT * from entrytest ORDER by RAND() LIMIT 20"; $result = mysql_query($query, $db); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { $answer[$i] = $row[5]; $question[$i] = $row['1']; $qnum[$i] = $i; $orgid[$i] = $row['id']; $ans1[$i] = $row[2]; $ans2[$i] = $row[3]; $ans3[$i] = $row[4]; $i++; } $user_answer = array(); $i = 0; $j = 1; print "<FORM ACTION='$PHP_SELF' METHOD='post'><BR>\n"; while ($j <= 20) { print "Question #" . $j . ': ' . "<b>".$question[$i]."</b><BR>\n"; print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='A'>".$ans1[$i]."<BR>\n"; print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='B'>".$ans2[$i]."<BR>\n"; print "<INPUT TYPE='radio' NAME='user_answer[" . $i . "]' VALUE='C'>".$ans3[$i]."<P><P>\n"; $i++; $j++; } //print "<INPUT TYPE='hidden' NAME='qkey' VALUE='$questionkey'>\n"; $ii=0; while ($ii<=19) { print "<input type='hidden' name='answer[$ii]' value='$answer[$ii]'>\n"; print "<input type='hidden' name='orgid[$ii]' value='$orgid[$ii]'>\n"; $ii++; } print "<input type='hidden' name='email2' value='$email'>\n"; print "<input type='hidden' name='testid2' value='$testid'>\n"; print "<input type='hidden' name='name2' value='$name'>\n"; print "<INPUT TYPE='hidden' NAME='useraction' VALUE='checkit'>\n"; print "<INPUT TYPE='submit' NAME='submitted' VALUE='Submit Test'>\n"; print "</FORM><br>\n"; } //Security End else { echo "Sorry, this test has expired."; } } else { // <!-- if submitted, check the answers on the form --> $query_entrytestcomplted = "SELECT * FROM entrytestcompleted where email = '$email2'"; $entrytestcomplted = mysql_query($query_entrytestcomplted, $conn_abrv) or die(mysql_error()); $row_entrytestcomplted = mysql_fetch_assoc($entrytestcomplted); $totalRows_entrytestcomplted = mysql_num_rows($entrytestcomplted); if($totalRows_entrytestcomplted != "0") { echo "This test has already been submitted. Sorry champ"; } else { $i=0; $correct = 0; $incorrect = 0; foreach ($_POST['orgid'] as $k =>$v) { $orgid[$k] = $v; } $k = 0; $m = 0; while ($k <= 19) { if ($_POST['user_answer'][$k] == $answer[$k]) { $correct++; unset ($_POST['user_answer'][$k]); unset ($orgid[$k]); } else { $incorrect++; } $k++; } $percent = $correct*5; echo "<br><br>"; print "You answered $correct questions correctly and $incorrect questions incorrectly. This eqautes to $percent%<br>"; if($correct >= 14) { echo "<br><br><font color=#006600><b>Well done! You passed the entry test</b></font>. Heres our <a href=\"applicationform.php?testid=$testid2\">application form</a><br><br>"; } elseif ($correct > 10) { echo "<br><br>You fell a bit short of a passing grade this time. You were close to our cutoff point so dont be afraid to try again<br><br>"; } else { echo "<br><br>Sorry, unfortunately you havent reached the high standard we require<br><br>"; } } $entrytestcomplete = "INSERT into entrytestcompleted VALUES ('$testid2', NOW(), '$email2', 'Yes', '$correct', '$percent', '$name2')"; $resultcompletetest = mysql_query($entrytestcomplete); } // original if ?> Hi there. The above script pulls a random test from the database and displays 20 questions from the database. Once the test is submitted it checks from the database to see if the answers are correct and also inserts ‘Yes’ into the entrypending test database. Although I'm having problems with the above script in that every time I submit the test it outputs the error "Sorry, this test has expired". This must mean the script isn’t getting past the security check? I recently got a new host that uses a newer php version and this script worked fine before on the older php version. Can anybody spot any errors that would cause this script not to work on a newer php version? I’m really stuck for ideas on this one. Sorry for posting so much of the script. Thanks
  3. I keeping getting an error on both Teds and Kens scripts. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
  4. There seems to be a syntax error on line 6?
  5. Column Name = online_time Table Name = users Above - Best example I can find
  6. The output I want is something like 00:00:00 (H:i:s) What I mean about the minutes/seconds is that if you normally count hours, minutes and seconds up you get the wrong output. For example if I add up 1 hour, 30 minutes against 1 hour, 25 minutes I want the output to be 02:55:00 rather than just 255.
  7. No luck with that script ted_chou12. What I basically want to do is total up all the hours in the database and echo them taking into consideration how many minutes/seconds there is in an hour. In my database there are over 30 totals to add up. Thanks
  8. Thanks for that. Although in most cases I'll be counting hours from a database so I won't be able to convert the hours to seconds. For example <?php $sql = mysql_query("SELECT SUM(online_time) AS count FROM users"); $count = mysql_result($sql, 0, 'count'); echo "$count"; ?> In my database all the times (online_time) are in the format of hh:mm:ss (00:00:00)
  9. Hi How do I count up hours in php taking into consideration that there are 60 minutes in an hour and 60 seconds in a minute? For example if I want to count 01:25:00 and 01:30:00 taking into consideration that there are 60 minutes in an hour. If I were to count the two normally in php it would add up to, 2 but I want it to add up to 02:55:00. How would I do that? Cheers
  10. [quote author=pocobueno1388 link=topic=124432.msg515508#msg515508 date=1170008769] Hmmm...doesn't look any different to me. Are you sure you defined $name? What is the error, or what is happening? [/quote] I never had to define it before.. simply the name is gotten from the url eg user.php?name=Andrew The only thing that is happening is that I can't see the results displayed... no error messages or anything. [quote author=Destruction link=topic=124432.msg515515#msg515515 date=1170009248] What is $name in this line: $query_users = "SELECT * FROM user where name = '$name'"; If you're not doing something like $name = $_GET['name']; (missed filtering input out for simplicity) then it's because you were using register_globals before and that isn't supported now. Dest [/quote] Cheers Dest I’ve got it working now with the $name = $_GET['name']; added in above the query.  Would anybody know how to modify the $name = $_GET['name']; inorder to add this function… $name = mysql_real_escape_string($name); Cheers Again
  11. I recently got a new web host that uses a newer .php version.  I've just realized that my scripts don't appear to work with it. For example the scripts that pull information from the database by a name or an id in the URL etc don't work. users.php?name=Bob [code]$query_users = "SELECT * FROM user where name = '$name'"; $users = mysql_query($query_users) or die(mysql_error()); $row_users = mysql_fetch_assoc($users);[/code] Anybody have any clue how to fix this as I'm really stuck. Thanks
  12. Hi I’m a few problems in that people are inserting HTML into my database and then it being displaying on my site, for example on user profiles. How do I stop html being display so for example if a user inserts this, <strong>Andrew</strong> that it wouldn’t display in the format Andrew and rather output like this <strong>Andrew</strong>?  I’m also thinking that if people can insert html they there’s nothing stopping them inserting php and getting private information of the database. Cheers.
  13. Hi Anybody have any idea why I'm getting a SQL syntax error on this script SQL query? [code]mysql_query("INSERT INTO messages (to, subject) VALUES ('$to', '$subject')") or die (mysql_error());[/code] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to, subject) VALUES ('Andrew', '456456',)' at line 1 Cheers
  14. Cheers for the help.  Is there any other ways I could protect my inputs and outputs?
  15. Hi guys. What is the recommend way to protect against an SQL injection on the following query? [code]$query_qy = "SELECT * FROM tablename where name = '$name' && date = '$date'"; $qy= mysql_query($query_qy) or die(mysql_error()); $row_qy = mysql_fetch_assoc($qy);[/code] Cheers
  16. Can anybody tell me why this script below isn't working.  As you can see if page = names it will echo that.  The problem is inside the echo I have some php.  I tried putting the php in "" but it still comes up with an error. [code]    <? if ($page == 'names'){ echo"</td>   </tr>   <tr class=\"navtext2\">     <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\">               <div align=\"left\"><font color=\"#747474\">" echo $row_names['fullname']; "</font></div>       </div>       <div>         <div align=\"left\"></div>       </div>       <div></div></td>   </tr>"; } ?>[/code]
  17. Thanks for your help although I'm still having problems. The result is not correct as its displaying 06:40 when it should be 00:04. I simply want to add 00:01:00 and 00:03:00 from the database colunm 'duration' and have a result of 00:04 or another example 00:60:00 and 00:30:00 and have a result of 01:30.
  18. Hi I'm having a few problems counting in php and displaying the results in the right format.  For example if I want to count these values (below) [img]http://img459.imageshack.us/img459/3134/1uq9.jpg[/img] The code I'm using: (below) [code]<?php $sql = mysql_query("SELECT SUM(duration) AS count FROM reports"); $count = mysql_result($sql, 0, 'count'); $total = $count; echo floor($count / 60) . ":" . ($count % 60); ?>[/code] When I use this code (above) to count the values I get 6:40 which clearly isn't right. How do i format this above script to display the result in the right format, hh:mm:ss, 00.05.00 ? Cheers
  19. Cheers  :), although its still not working. Somehow I need a script that if Day does = Any it will not just pick the first if statement that applies to Day = Any.  I need it to search through all the statements to find the right one.  So if all the values (day, aircraft, departure, arrival) = Any it will find that if statement. Cheers
  20. Hi, I was wondering why this script (below) isn't working.  For example, when the inputs, day, aircraft, departure, arrival = Any, why does the echo, "Day, Aircraft, Departure, Arrival = Any" not display? [code]$day=$_POST["day"]; $aircraft=$_POST["aircraft"]; $departure=$_POST["departure"]; $arrival=$_POST["arrival"]; if ($day == "Any") { echo 'Day = Any'; } elseif ($aircraft == "Any") { echo 'Aircraft = Any'; } elseif ($departure == "Any") { echo 'Departure = Any'; } elseif ($arrival == "Any") { echo 'Arrival = Any'; } elseif ($day && $aircraft && $departure && $arrival == "Any") { echo 'Day, Aircraft, Departure, Arrival = Any'; } [/code] Cheers
  21. Thanks printf and shiny_spoon, I want it so that above 25 and less than 75 is First Officer and anything below 25 is Training Officer.  I'm having a few problems with it though, the ranks only seem to be changing on whole numbers, i.e. training officer wil only change to first officer if hours are 30 or over when I want it to change at 25 or over?  Is there a way I can get around this? Cheers again.
  22. Can anybody tell me why this script below that calculates a pilot rank is not working.  I'm getting a Parse error: parse error, unexpected '<' . As you can see in the else if statement if the 'flthrs' is bigger than 25 but less and 75 it will insert 'First Officer into the database. How do you write these sort of statements correctly? [code]if ($user_array['flthrs'] > '25'){ $rank = 'Training Officer'; } else if ($user_array['flthrs'] > '25' & < '75'){ $rank = 'First Officer'; }[/code] Cheers!
  23. Hi How would I subtract 1 hour from this time function [code]$time = date('H:i');[/code] Cheers  :)
×
×
  • 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.