Web Design Forum: Small PHP Help - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Small PHP Help Rate Topic: -----

#1 User is offline   adamjhunt 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 114
  • Joined: 11-January 09
  • Reputation: 1
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 08:35 PM

Hello everyone,

I wondered if someone could help, as this is majorly stressing me out!

I have a PHP quiz, that when completed sends the score and session username to the table quiz.

I want to be able to only allow them to complete the quiz once. So IF the session username is already in the quiz table echo 'you can only do the quiz once' else echo 'you have 1 quiz to be taken'

If anyone could help, i would massively appreciate it!

Thanks
0

#2 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 17 March 2010 - 07:25 AM

change to suit you but something like :
$user_name = $_SESSION["username"];
$query = "SELECT quizdone from users WHERE username = $user_name limit 0,1";
$result = mysql_query($query) or die('Query failed: ' . mysql_error()); unset($query);// fetch result set and free resources
if (!$result){
  echo "sorry there was an error"; // simple error checking
  exit; // if error then stop form 
 } 
 else  
 {  
  $row = mysql_fetch_row($result) unset($result);    //fetch single row and free resources
  if($row[0] === "true") //check if quizdone is true
  {
    echo "you have done this before";
  }
 }

0

#3 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,814
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 17 March 2010 - 09:51 AM

You could also set a cookie, store the visitors IP in your table - not definate ways to determine if someone has taken the quiz, but enought to put people off.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users