Jump to content

[SOLVED] update not working really need help i need the project


Danny620

Recommended Posts

hi i am programming a online quiz where the pupils login and do the quiz and the scores get subminted back to the teacher but the thing is when the users do the quiz again it does not update there scores

 

heres my code any help would be helpful

 

<?php 
$page_title = 'Login';
include ('includes/header.html');
define ('MYSQL', 'includes/mysqli_connect.php');
require_once (MYSQL);
$question1 = $question2 = $question3 = $question4 = $question5 = $question6 = $question7 = $question8 = $question9 = 0;

if(isset($_POST['sent'])){

	if(isset($_POST['group1'])){

	$question1 = $_POST['group1'];

	}

	if(isset($_POST['group2'])){

	$question2 = $_POST['group2'];

	}

	if(isset($_POST['group3'])){

	$question3 = $_POST['group3'];

	}

	if(isset($_POST['question4'])){

	$question4 = $_POST['question4'];

	}

	if(isset($_POST['question5'])){

	$question5 = $_POST['question5'];

	}

	if(isset($_POST['question6'])){

	$question6 = $_POST['question6'];

	}

	if(isset($_POST['question7'])){

	$question7 = $_POST['question7'];

	}

	if(isset($_POST['question8'])){

	$question8 = $_POST['question8'];

	}

	if(isset($_POST['question9'])){

	$question9 = $_POST['question9'];

	}
	}

$result = $question1 + $question2 + $question3 + $question4 + $question5 + $question6 + $question7 + $question8 + $question9;

$percent = $question1 + $question2 + $question3 + $question4 + $question5 + $question6 + $question7 + $question8 + $question9;

	$resultp = floor($percent/9 * 100);

	//results bit
	$user = $_SESSION['user_id'];

	//check for if done question

	$q = "SELECT score FROM scores WHERE user_id = '$user' AND strand = '7h2.63e2' LIMIT 1";
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . 		        mysqli_error($dbc));
	mysqli_fetch_array ($r, MYSQLI_ASSOC); 

	if (@mysqli_num_rows($r) == 1) { // A match was made.

		//check to see if the score they have scored now is higher than the one in the db.
		$q = "UPDATE score SET score='$resultp', attempts='2' WHERE user_id = $user LIMIT 1";
		$r = @mysqli_query ($dbc, $q);
		if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

			// Print a message:
			echo '<p>Your New score has been changed</p>';	

		}
		}elseif(@mysqli_num_rows($r) == 0) {


	$q = "INSERT INTO scores (`user_id`, `strand`, `score`, `attempts`) VALUES ('$user','7h2.63e2', '$resultp', '1')";

	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . 		        mysqli_error($dbc));

	echo  "your result has been saved";

	}


?>
<style type="text/css">
<!--
.style1 {color: #F0F0F0}
-->
</style>

<form name="form1" method="post" action="">
  <label></label>
  <table width="610" height="1353" border="0" align="center">
    <tr>
      <td width="206" height="36"> </td>
      <td colspan="2"><?php if($result){ echo "Well Done You scored $result/9" ;}?><br /><?php if($resultp){ echo "Well Done You scored $resultp %";}?></td>
    </tr>
    <tr>
      <td height="32"> </td>
      <td width="167"><p>
        <label></label>
      </p></td>
      <td width="223"> </td>
    </tr>
    <tr>
      <td height="32" bgcolor="#CCCCCC">The ratio of moons to suns</td>
      <td bgcolor="#CCCCCC"><img src="images/sun.png" width="155" height="135" /></td>
      <td bgcolor="#CCCCCC"><p>
          <label></label>
          <label>
          <input type="radio" name="group1" id="radio8" value="0" />
            4.1<br />
          </label>
        </p>
          <p>
            <label></label>
            <label>
            <input type="radio" name="group1" id="radio9" value="1" />
            </label>
            <label></label>
            <label></label>
            1.4 </p>
        <p>
            <input type="radio" name="group1" id="radio10" value="0" />
          3:2</p>
        <p>
            <input name="group1" type="radio" id="radio11" value="0" />
          2:3</p></td>
    </tr>
    <tr>
      <td height="32"> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td height="30" bgcolor="#999999">The ratio of red to blue</td>
      <td bgcolor="#999999"><img src="images/shapes.png" width="155" height="135" /></td>
      <td bgcolor="#999999"><label>
        <input name="group2" type="radio" id="radio16" value="0" />
        2:6<br />
        <br />
        </label>
          <label>
          <input type="radio" name="group2" id="radio17" value="0" />
          </label>
          <label> 6:1<br />
          <br />
          <input type="radio" name="group2" id="radio18" value="1" />
          </label>
          <label> 6:2<br />
          <br />
          <input type="radio" name="group2" id="radio19" value="0" />
            6:3</label></td>
    </tr>
    <tr>
      <td height="30"><span class="style1"></span></td>
      <td><span class="style1"></span></td>
      <td><span class="style1"></span></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"><table cellspacing="0" cellpadding="0" hspace="0" vspace="0" align="left">
          <tr>
            <td valign="top" align="left"><p align="center">The    ratio of blue to red</p></td>
          </tr>
      </table></td>
      <td bgcolor="#CCCCCC"><img src="images/shapes2.png" width="155" height="135" /></td>
      <td bgcolor="#CCCCCC"><label>
        <input type="radio" name="group3" id="radio4" value="1" />
        3:5<br />
        <br />
        <input name="group3" type="radio" id="radio5" value="0" />
        5:3<br />
        <br />
        <input type="radio" name="group3" id="radio6" value="0" />
        4:4<br />
        <br />
        <input type="radio" name="group3" id="radio7" value="0" />
      5:2</label></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"><table cellspacing="0" cellpadding="0" hspace="0" vspace="0" align="left">
        <tr>
          <td valign="top" align="left"><p align="center">What    ratio of blue to green?</p></td>
        </tr>
      </table></td>
      <td bgcolor="#CCCCCC"><img src="images/shapes3.png" width="155" height="135"></td>
      <td bgcolor="#CCCCCC"><select name="question4" id="question4">
        <option value="0">1:7</option>
        <option value="1">7:1</option>
        <option value="0">1:8</option>
      </select></td>
    </tr>
    <tr>
      <td><table cellspacing="0" cellpadding="0" hspace="0" vspace="0" align="left">
        <tr>
          <td valign="top" align="left"><p align="center">The    ratio of blue to red</p></td>
        </tr>
      </table></td>
      <td><img src="images/shapes4.png" width="155" height="135"></td>
      <td><select name="question5" id="question5">
        <option value="0">6:2</option>
        <option value="0">2:5</option>
        <option value="1">2:6</option>
            </select></td>
    </tr>
    <tr>
      <td><table cellspacing="0" cellpadding="0" hspace="0" vspace="0" align="left">
        <tr>
          <td valign="top" align="left"><p align="center">The    ratio of pink to green</p></td>
        </tr>
      </table></td>
      <td><img src="images/shapes5.png" width="155" height="135"></td>
      <td><select name="question6" id="question6">
        <option value="1">3:1</option>
        <option value="0">1:3</option>
        <option value="0">3:3</option>
            </select></td>
    </tr>
    <tr>
      <td><table cellspacing="0" cellpadding="0" hspace="0" vspace="0" align="left">
        <tr>
          <td valign="top" align="left"><p align="center">The    ratio of squares to circles</p></td>
        </tr>
      </table></td>
      <td><img src="images/shapes6.png" width="155" height="135"></td>
      <td><select name="question7" id="question7">
        <option value="0">2:3</option>
        <option value="1">1:3</option>
        <option value="0">3:1</option>
            </select></td>
    </tr>
    <tr>
      <td>What ratio of green to blue?</td>
      <td><img src="images/shapes7.png" width="155" height="135"></td>
      <td><select name="question8" id="question8">
        <option value="0">2:7</option>
        <option value="1">2:6</option>
        <option value="0">6:2</option>
            </select></td>
    </tr>
    <tr>
      <td><table cellspacing="0" cellpadding="0" hspace="0" vspace="0" align="left">
        <tr>
          <td valign="top" align="left"><p align="center">The    ratio of legs to tails</p></td>
        </tr>
      </table></td>
      <td><img src="images/shapes8.png" width="155" height="135"></td>
      <td><select name="question9" id="question9">
        <option value="0">4:2</option>
        <option value="0">1:4</option>
        <option value="1">4:1</option>
            </select></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="button" id="button" value="Submit">
      <input name="sent" type="hidden" id="sent" value="TRUE" /></td>
      <td> </td>
    </tr>
  </table>
  <p>
    <label></label>
  </p>
  <p>
    <label></label>
  </p>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.