This is pretty detailed, but here goes. I have a user registration/log in system in place. I have no issues at all registering users or logging them in.

My database contains 5 tables. As follows

usersystem
Fields:
username
password
email
total
qid

q1
Fields:
username
answer
rank
value

Tables q2 & q3 are the same set up as q1. For each of these tables rank is the primary key and set to auto increment. For each of these I will have a dummy entry for calculations of value seen below so the first person to answer does not get a score of 0.


After the user logs in they are directed to play.php. They should be able to answer the question, and if it is correct, it submits it to table q1 and moves them to play1.php. I do not want them to be able to skip ahead and manually type in play1.php if they have no answered the question on play.php.

If they answer correctly first, they should be 100 points down to 50 points. There after, everyone who answers correctly will be given 50 points.

The only thing that is working at this point is the answers are being submitted to table q*. The rank is properly calculated, but the value automatically calculates even below 50 points. The qid of table usersystem also updates correctly. Also, if the user is not logged it, it will directly them to nogo.php properly.

I know there is a lot of code, but here it is, including the html aspects of it. I am getting no errors. I've put dummy questions and answers in until I get it functioning right. I'm really new to PHP and MySQL (within a few weeks) so any help would be really appreciated!

File: db.php

<?php
session_start(); 
mysql_connect("localhost", "dbuser", "dbpassword"); 
mysql_select_db("myDB");
{ 
if (isset($_POST['username']) && isset($_POST['password']))
{ 	$username = mysql_real_escape_string($_POST['username']); 
	$password = md5( mysql_real_escape_string($_POST['password']) );

	$sql = mysql_query("SELECT * FROM usersystem WHERE username = '$username' AND password = '$password' LIMIT 1"); 
	$rows = mysql_num_rows($sql); 
 
	if ($rows<1)
	{ 
	echo "[b]<FONT color=#CC0000 face='My Scars'> Incorrect username/password </FONT>[/b]"; 

	}
	else 
	{
	
	
$result = mysql_query("SELECT total FROM usersystem WHERE username = '$username'") or die( mysql_error() );
$row=mysql_fetch_assoc($result);
$total = $row['total'];

$rqid = mysql_query("SELECT qid FROM usersystem WHERE username = '$username'") or die( mysql_error() );
$rowqid=mysql_fetch_assoc($rqid);
$qid = $rowqid['qid'];

$_SESSION['username'] = $username;
setcookie("username", "$username", time()+3600);
setcookie("total", "$total", time()+3600);
setcookie("qid", "$qid", time()+3600);
header( "Location: play.php" );
exit();
	} 
}}
?>

File: play.php

<?php
include("db.php"); 
if ((isset($_COOKIE["username"])) && (isset ($_COOKIE["total"]))) {
$uname=$_COOKIE["username"];
$answer = mysql_real_escape_string($_POST['answer1']); 
if ($answer == "Cheryl") {
mysql_query("INSERT INTO q1 (username, answer) VALUES ( '$uname', '$answer')") or die (mysql_error());
$q1id = 1;
mysql_query("UPDATE usersystem SET qid='$q1id' WHERE username = '$uname'");

$setup = mysql_query("SELECT rank FROM q1 WHERE username = '$uname'") or die (mysql_error());
$gotit=mysql_fetch_assoc($setup);
$rank = $gotit['rank'];
if ($rank == 1) {$value = 100;}
else {if (($rank <<11) && ($rank >>1)) {$value = (100 - (($rank-1)*5));}
else {$value = 50;}}
mysql_query("UPDATE q1 SET value='$value' WHERE username = '$uname'") or die (mysql_error ());
header ('Location: play1.php');



}
$ck=$_COOKIE["qid"];
if ($ck >>0) {
header ('Location: play1.php');}



}
else {
header('Location: nogo.php');
}



?>







<HTML>
<HEAD>
<TITLE>Play Time</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</HEAD>
<BODY BGCOLOR=#000000 LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<IMG SRC="images/moribg.gif" WIDTH=883 HEIGHT=580 ALT=""> 
<div id="layer_name" style="position:absolute; width:422px; height:38px; z-index:1; left: 4px; top: 8px;"><font color="#CC0000" size="+2" face="My Scars">
<?php 
print ("Username: " . $_COOKIE["username"]);
?>
</font></div> 
  
<div id="layer_score" style="position:absolute; width:422px; height:38px; z-index:1; left: 452px; top: 8px;"><font color="#CC0000" size="+2" face="My Scars">
<?php 
print ("Score: " . $_COOKIE["total"]);
?>
</font></div> 



<div id="layer_answer" style="position:absolute; width:422px; height:232px; z-index:3; left: 447px; top: 113px;"><font color="#CC0000" size="+2" face="My Scars"> 
  <form action="play.php" method="post" name="answerform">
    <div align="center">
      <p>&nbsp;</p>
      <p>
        <input type="text" name="answer1" STYLE="color: #CC0000; font-family: My Scars; font-size: 20px;">
      </p>
      <p>
        <input type="submit" name="Submit" value="Answer" 
	style="color: #000000; font-family: My Scars; font-size: 20px; background-color: #CC0000; border='0'">
      </p>
    </div>
  </form> </font></div>
<div id="layer_question" style="position:absolute; width:422px; height:234px; z-index:2; left: 4px; top: 113px;"> 
  <p><font color="#CC0000" size="+6" face="My Scars"> Question Holder space:</font></p>
  <p>&nbsp;</p>
  <p><font color="#CC0000" size="+6" face="My Scars">What is my name?</font></p>
</div>
</BODY>
</HTML>

play1.php

<?php
include("db.php"); 
if ((isset($_COOKIE["username"])) && (isset ($_COOKIE["total"]))) {
$uname=$_COOKIE["username"];
$answer = mysql_real_escape_string($_POST['answer2']); 
if ($answer == "North Carolina") {
mysql_query("INSERT INTO q2 (username, answer) VALUES ( '$uname', '$answer')") or die (mysql_error());
$q1id = 2;
mysql_query("UPDATE usersystem SET qid='$q1id' WHERE username = '$uname'");

$setup = mysql_query("SELECT rank FROM q2 WHERE username = '$uname'") or die (mysql_error());
$gotit=mysql_fetch_assoc($setup);
$rank = $gotit['rank'];
if ($rank == 1) {$value = 100;}
else {if (($rank <<11) && ($rank >>1)) {$value = (100 - (($rank-1)*5));}
else {$value = 50;}}
mysql_query("UPDATE q2 SET value='$value' WHERE username = '$uname'") or die (mysql_error ());
header ('Location: play2.php');




}

$ck=$_COOKIE["qid"];
if ($ck >>1) {
header ('Location: play2.php');}
else {
if ((!($ck == 1)) && ($ck <<1)){
header ('Location: play.php');
}
}


}
else {
header('Location: nogo.php');
}



?>







<HTML>
<HEAD>
<TITLE>Play Time</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</HEAD>
<BODY BGCOLOR=#000000 LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<IMG SRC="images/moribg.gif" WIDTH=883 HEIGHT=580 ALT=""> 
<div id="layer_name" style="position:absolute; width:422px; height:38px; z-index:1; left: 4px; top: 8px;"><font color="#CC0000" size="+2" face="My Scars">
<?php 
print ("Username: " . $_COOKIE["username"]);
?>
</font></div> 
  
<div id="layer_score" style="position:absolute; width:422px; height:38px; z-index:1; left: 452px; top: 8px;"><font color="#CC0000" size="+2" face="My Scars">
<?php 
print ("Score: " . $_COOKIE["total"]);
?>
</font></div> 



<div id="layer_answer" style="position:absolute; width:422px; height:232px; z-index:3; left: 447px; top: 113px;"><font color="#CC0000" size="+2" face="My Scars"> 
  <form action="play1.php" method="post" name="answer2form">
    <div align="center">
      <p>&nbsp;</p>
      <p>
        <input type="text" name="answer2" STYLE="color: #CC0000; font-family: My Scars; font-size: 20px;">
      </p>
      <p>
        <input type="submit" name="Submit" value="Answer" 
	style="color: #000000; font-family: My Scars; font-size: 20px; background-color: #CC0000; border='0'">
      </p>
    </div>
  </form> </font></div>
<div id="layer_question" style="position:absolute; width:422px; height:234px; z-index:2; left: 4px; top: 113px;"> 
  <p><font color="#CC0000" size="+6" face="My Scars"> Question Holder space:</font></p>
  <p>&nbsp;</p>
  <p><font color="#CC0000" size="+6" face="My Scars">Where do I live?</font></p>
</div>
</BODY>
</HTML>

To save room, play2.php and play3.php are set up the same way, except its such as q2 are changed to be appropriate and the values for checking the qid are adjusted as well.

What's wrong here?

Recommended Answers

All 2 Replies

I think that using the bitwise operators (<< and >>) are causing problems.

Try using < and > instead.

Perfect! Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.