Jump to content

Help with Enrollment page for my Capstone Project


ray92

Recommended Posts

Hey all

I'm very beginners level and I realize now that my group have chosen a project for our capstone that is beyond our knowledge, I was able to create a Login and Registration pages without issues and am also able to save it in the database but I have been struggling to understand why am I getting the two errors bellow.

 

Quote

 

Warning: Undefined array key "login" in C:\xampp\htdocs\aih\index2.php on line 41

Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\aih\index2.php:43 Stack trace: #0 C:\xampp\htdocs\aih\index2.php(43): mysqli_fetch_array(false) #1 {main} thrown in C:\xampp\htdocs\aih\index2.php on line 43

 

 

What I'm trying to achieve is displaying the 'studentid' and save all the information input on the form in the table 'courseenrolls'.

If anyone could enlighten me with what's wrong and how to solve would be much appreciated.

Here is the code for the index page.

 

session_start();
  include('config2.php');
  include('dbconn.php');

if(isset($_POST['submit_enrol']))
{
$studentid=mysqli_real_escape_string($_POST['studentid']);
$year=mysqli_real_escape_string($_POST['year']);
$term=mysqli_real_escape_string($_POST['term']);
$coursetimetable1=mysqli_real_escape_string($_POST['coursetimetable1']);
$coursetimetable2=mysqli_real_escape_string($_POST['coursetimetable2']);
$coursetimetable3=mysqli_real_escape_string($_POST['coursetimetable3']);
$coursetimetable4=mysqli_real_escape_string($_POST['coursetimetable4']);

$ret= mysqli_query ($con,"INSERT INTO courseenrolls(studentid,year,term,coursetimetable1,coursetimetable2,coursetimetable3,coursetimetable4) 
  VALUES ('$studentid','$year','$term',$coursetimetable1','$coursetimetable2','$coursetimetable3', 'coursetimetable4')");
  mysqli_query($db, $query);
if($ret)
{
$_SESSION['msg']="Enrolled Successfully!";
}
else
{
  $_SESSION['msg']="Error: Not Enrolled";
}
}

?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Course Enrolment</title>
  <link rel="stylesheet" type="text/css" href="style2.css">
</head>
<body>
<font color="green" align="center"><?php echo htmlentities($_SESSION['msg']);?><?php echo htmlentities($_SESSION['msg']="");?></font>

<?php $sql=mysqli_query($con,"SELECT * from user where studentid='".$_SESSION['login']."'");
$cnt=1;
while($row=mysqli_fetch_array($sql))
  ?>

<div class="panel-body">
<form name="term" method="post" enctype="multipart/form-data">
 <div class="form-group">
     <label for="studentid">Student ID   </label>


    <input type="text" class="form-control" id="studentid" name="studentid" value="<?php echo htmlentities($row['studentid']);?>"  placeholder="studentid" readonly />
    
  </div>
<?php  ?>
<div class="form-group">
    <label for="year">Select Your Current Study Year  </label>
    <select class="form-control" name="year" required="required">
   <option value="">Select Your Current Study Year</option>   
   <?php 
$sql=mysqli_query($con,"select * from year");
while($row=mysqli_fetch_array($sql))
{
?>
<option value="<?php echo htmlentities($row['year']);?>"><?php echo htmlentities($row['year']);?></option>
<?php } ?>
    </select> 
  </div>



<div class="form-group">
    <label for="term">Select The Term You are Enrolling In  </label>
    <select class="form-control" name="term" required="required">
   <option value="">Select The Term You are Enrolling In</option>   
   <?php 
$sql=mysqli_query($con,"select * from term");
while($row=mysqli_fetch_array($sql))
{
?>
<option value="<?php echo htmlentities($row['term']);?>"><?php echo htmlentities($row['term']);?></option>
<?php } ?>

    </select> 
  </div> 


<div class="form-group">
    <label for="coursetimetable1">Select First Course  </label>
    <select class="form-control" name="coursetimetimetable1" required="required">
   <option value="">Select First Course</option>   
   <?php 
$sql=mysqli_query($con,"select * from coursetimetable1");
while($row=mysqli_fetch_array($sql))
{
?>
<option value="<?php echo htmlentities($row['courseday']);?>"><?php echo htmlentities($row['courseday']);?></option>
<?php } ?>

    </select> 
  </div> 

  <div class="form-group">
    <label for="coursetimetable2">Select Second Course  </label>
    <select class="form-control" name="coursetimetimetable2">
   <option value="">Select Second Course</option>   
   <?php 
$sql=mysqli_query($con,"select * from coursetimetable2");
while($row=mysqli_fetch_array($sql))
{
?>
<option value="<?php echo htmlentities($row['courseday']);?>"><?php echo htmlentities($row['courseday']);?></option>
<?php } ?>

    </select> 
  </div>  

<div class="form-group">
    <label for="coursetimetable3">Select Third Course    </label>
    <select class="form-control" name="coursetimetable3">
   <option value="">Select Third Course</option>   
   <?php 
$sql=mysqli_query($con,"SELECT * FROM coursetimetable3");
while($row=mysqli_fetch_array($sql))
{
?>
<option value="<?php echo htmlentities($row['courseday']);?>"><?php echo htmlentities($row['courseday']);?></option>
<?php } ?>

    </select> 
  </div>
<div class="form-group">
    <label for="coursetimetable4">Select Fourth Course    </label>
    <select class="form-control" name="coursetimetable4">
   <option value="">Select Fourth Course</option>   
   <?php 
$sql=mysqli_query($con,"SELECT * FROM coursetimetable4");
while($row=mysqli_fetch_array($sql))
{
?>
?>
<option value="<?php echo htmlentities($row['courseday']);?>"><?php echo htmlentities($row['courseday']);?></option>
<?php } ?>

    </select> 
  </div>
 <button type="submit_enrol" name="submit_enrol" id="submit_enrol" class="btn btn-default">Enroll</button>

 <button><a href="logout.php" class="btn btn-default">Logout</a> </button>;
</div>

</form>
</body>
</span>
</div>
</form>
</div>
</body>
</html>

 

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.