<?php session_start() ?>

<!DOCTYPE html>

<!--[if IE 8]>			<html class="ie ie8"> <![endif]-->

<!--[if IE 9]>			<html class="ie ie9"> <![endif]-->

<!--[if gt IE 9]><!-->	<html><!--<![endif]-->



<!-- Specific Page Data -->



<!-- End of Data -->



<?php include('hhead.html'); ?>

  

  

  

  <?php

    function do_alert($msg) 

    {

        echo '<script type="text/javascript">alert("' . $msg . '") 

           parent.location="downscore.php";



</script>';

       

    }

?>

<?php

$tyr=$_SESSION['num'];



//make the database connection

include('config.php');

$sql = "select * from access where userid = '$tyr' ";

 $data = mysqli_query($conn,$sql);



$rows = mysqli_num_rows($data);



if($rows <= 0){

   do_alert("user does not exist contact system admin");

}

else{



while($row= mysqli_fetch_array($data))

{



$serial=  $row['name'];

 $input= $row['userid'];

$class=  $row['class'];

 $arm= $row['arm'];

 $email= $row['date'];

$clay="$class$arm";

$dfrd="subjects";

$sdc="$clay$dfrd";

$_SESSION['name']=$serial;



$_SESSION['num']=$input;

$_SESSION['clay']=$clay;

$_SESSION['email']=$email;

$_SESSION['sdz']=$sdc;



}



}



$ubjects="subjects";

$sdc="$clay$ubjects";





$_SESSION['subb']=$sdc;

$sql = "select subjects,class,type

 from `subjects` where staffid='$tyr' ";

 $data = mysqli_query($conn,$sql);







$rows4 = mysqli_num_rows($data);



$lcclass=strtolower($clay);

$_SESSION['lclay']=$lcclass;



$sql = "select * from `beva1` where password='$lcclass' ";

 $data = mysqli_query($conn,$sql);







$rows44 = mysqli_num_rows($data);



// Above will output ---- > testValue 











$sql = "SELECT MAX(serialno) AS maxid FROM subjects ";

          

          $data = mysqli_query($conn,$sql);

    $result = mysqli_fetch_assoc($data);



          





$pe=  $result['maxid'];





$se= $pe + 1;



$eer=$_SESSION['num'];

$obo10=$eer;



if(isset($_POST["idty"]))

{

	

	$stu=$_POST["idty"];

}















?>



  

  

  









<?php



$connect = mysqli_connect("localhost", "root", "plugg", "portalsms");

$message = '';



if(isset($_POST["upload"]))

{

 if($_FILES['product_file']['name'])

 {

  $filename = explode(".", $_FILES['product_file']['name']);

  if(end($filename) == "csv")

  {

   $handle = fopen($_FILES['product_file']['tmp_name'], "r");

   while($data = fgetcsv($handle))

   {

     $id = mysqli_real_escape_string($connect, $data[0]);

    $name = mysqli_real_escape_string($connect, $data[1]);  

                $cat1 = mysqli_real_escape_string($connect, $data[2]);

    $ca1 = mysqli_real_escape_string($connect, $data[3]);

	    $cat2 = mysqli_real_escape_string($connect, $data[4]);

		    $ca2 = mysqli_real_escape_string($connect, $data[5]);

			    $ex = mysqli_real_escape_string($connect, $data[6]);

				  

    $query = "

     UPDATE `year11amber` 

     SET code = '$cat1', 

    weeklytest = '$ca1',



cod = '$cat2', 

    week1 = '$ca2',



  ex = '$ex'

  

     WHERE regno = '$id' and subjects='$name'

    ";

    mysqli_query($connect, $query);

	

	$query = "

	 UPDATE `year11amber` 

     SET subject1 = code+weeklytest, 

    d1 = cod + week1,

tot=ex+d1+subject1

  

WHERE regno = '$id' and subjects='$name'

    ";

    mysqli_query($connect, $query);

   }

   fclose($handle);

   header("location: upscores.php?updation=1");

  }

  else

  {

   $message = '<label class="text-danger">Please Select CSV File only</label>';

  }

 }

 else

 {

  $message = '<label class="text-danger">Please Select File</label>';

 }

}



if(isset($_GET["updation"]))

{

 $message = '<label class="text-success">Product Updation Done</label>';

}



$query = "SELECT regno,name,subjects,code,weeklytest";

$result = mysqli_query($connect, $query);

?>

<!DOCTYPE html>

<html>

 <head>

  <title>Update Mysql Database through Upload CSV File using PHP</title>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

 </head>

 <body>

  <br />

  <div class="container">

   <h2 align="center">Update Mysql Database through Upload CSV File using PHP</a></h2>

   <br />

   <form method="post" enctype='multipart/form-data' action="upload5.php">

   

    <div class="form-group">

                        <label class="col-sm-4 control-label">Select Subjects</label>

                        <div class="col-sm-7 controls">

                        

						  

						 <?php

$sql = ("select * from `t_$obo10` ") ;

$result = $conn->query($sql);// Run your query



echo '<select name="idty" >'; // Open your drop down box



// Loop through the query results, outputing the options one by one

while($row = $result->fetch_assoc()) {

   echo '<option value="'.$row['serialno'].'">'.$row['subjects'].' '.$row['class'].''.$row['type'].'</option>';

}



echo '</select>';// 



?>               </div>

                      </div>

    <p><label>Please Select File(Only CSV Formate)</label>

    <input type="file" name="product_file" /></p>

    <br />

    <input type="submit" name="upload" class="btn btn-info" value="Upload" />

   </form>

   <br />

   <?php echo $message; ?>

   <h3 align="center">Deals of the Day</h3>

   <br />

   <div class="table-responsive">

    <table class="table table-bordered table-striped">

     <tr>

      <th>Category</th>

      <th>Product Name</th>

      <th>Product Price</th>

     </tr>

     <?php

     while($row = mysqli_fetch_array($result))

     {

      echo '

      <tr>

       <td>'.$row["product_category"].'</td>

       <td>'.$row["product_name"].'</td>

       <td>'.$row["product_price"].'</td>

      </tr>

      ';

     }

     ?>

    </table>

   </div>

  </div>

 </body>

</html>



