Jump to content

Need help with simple code


MjM8082

Recommended Posts

Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this...

 

 

if grade_type >=100

 

$final_grade = A

 

 

Idk, im new to php and need help doing this... here is my code...

 

 

 

 

 

<?php

ini_set ("display_errors", "1");
error_reporting(E_ALL);

require_once('database.php');
session_start();






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




	$query		= "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) ";
	$query		.= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) ";

	$statement	= $db->prepare($query);
	$statement->bindValue (':student_id', $_SESSION['student_id']);
	$statement->bindValue (':grade_id', $_SESSION['grade_id']);
	$statement->bindValue (':grade_type', $_POST['grade_type']);
	$statement->bindValue (':grade_name', $_POST['grade_name']);
	$statement->bindValue (':grade_points', $_POST['grade_points']);

	$statement->execute();

	$statement->closeCursor();






	}





?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View Course Grades</title>

<link rel="stylesheet" type="text/css" href="main.css" />
</head>

<body>


    



<?php

$student_name = $_SESSION['student_name'];
$student_id = $_SESSION['student_id'];
$query		= "SELECT * FROM grades WHERE student_id = :student_id ";

$statement	= $db->prepare($query);
$statement->bindValue (':student_id', $student_id);
$statement->execute();
$grades		= $statement->fetchAll();
$statement->closeCursor();


echo "<h1>Show Grades for $student_name </h1>";

	foreach ($grades as $grade)
{

	echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />";
}





?>

	<div id="content">
            <!-- display a table of products -->
            
            <table>
                <tr>
                    <th>Grade Type</th>
                    <th>Grade Name</th>
                    <th>Grade Points</th>
                    <th>Remove</th>
                </tr>
                <?php foreach ($grades as $grade) : ?>
                <tr>
                    <td><?php echo $grade['grade_type'];   ?></td>
                    <td><?php echo $grade['grade_name'];   ?></td>
                    <td><?php echo $grade['grade_points']; ?></td>
                    <td><form action="delete_grade.php" method="post">
                        
                        <input type="submit" name="remove" value="Delete" />
					<input type="submit" name="update" value="Update" />



                    </form></td>
                </tr>
                <?php endforeach; ?>
            </table>
            
        </div>
    </div>

    <div id="footer">
       
    </div>






<form name="grades" method="post" action="grades.php">

	<p>Grade Type<SELECT NAME="grade_type">
	<OPTION VALUE="Mid-Term">Mid-Term
	<OPTION VALUE="Final">Final
	<OPTION VALUE="Lab">Lab
	</SELECT>
	<br>







	Grade Name:<input type="text" name="grade_name" value=""><br />
	Grade Points:<input type="text" name="grade_point" value="">

	<input type="submit" name="add_grade" value="Add Grade">


	</form>

</table>

</body>

</html>

 

 

 

<html>
<head>
<title>Delete Grade</title>
</head>
<body>
<form method="post" action="delete_grade.php">

<?php


			ini_set ("display_errors", "1");
			error_reporting(E_ALL);

	$dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') 
	or die(mysql_error());

	//delete grades

	if (isset($_POST['remove']))
{          
	foreach($_POST['delete'] as $delete_id)
{             
	$query = "DELETE FROM grades WHERE grade_id = $delete_id";             
	mysqli_query($dbc, $query) or die ('can\'t delete user');          
}        
	echo 'grade has been deleted.<br />';   
}

	if (isset($_POST['update']))
{          
	foreach($_POST['update'] as $update_id)
	{             
		$query = "UPDATE grades SET grade_id = $update_id";             
		mysqli_query($dbc, $query) or die ('can\'t update user');    
       
	}
	}

	//Display grade info with checkbox to delete  
	$query = "SELECT * FROM grades";  
	$result = mysqli_query($dbc, $query);  
	while($row = mysqli_fetch_array($result))
{      
	echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; 
	echo ' ' .$row['grade_type'] .' '. $row['grade_name'];
	echo '<br />';  
}
	mysqli_close($dbc);

?>

<p>Grade Type<SELECT NAME="grade_type">
	<OPTION VALUE="Mid-Term">Mid-Term
	<OPTION VALUE="Final">Final
	<OPTION VALUE="Lab">Lab
	</SELECT>
	<br>







	Grade Name:<input type="text" name="grade_name" value=""><br />
	Grade Points:<input type="text" name="grade_point" value="">

<input type="submit" name="remove" value="Remove" />
<input type="submit" name="update" value="Update" />

</form>
</body>
</html>

Link to comment
Share on other sites

Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this...

 

If the stupid...instead of student.  that's pretty damn funny.

 

You can add $final_grade inside another column and row in the table in the first file you showed us.

Link to comment
Share on other sites

I want to display it underneath the table. I want it to say "Your Final Grade Is... "

 

 

I'm not sure where to put the code, but I tried to put it into my code as this...

 

 

if ($grade_points >= 100)

{

    $final_grade = 'A';

}

 

 

 

But it keeps saying grade_points is undefined

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.