Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sreebhattacharyya authored Nov 25, 2019
1 parent 2215123 commit cc5b0ee
Show file tree
Hide file tree
Showing 19 changed files with 721 additions and 138 deletions.
35 changes: 35 additions & 0 deletions MakeNewQp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
session_start();
$con=mysqli_connect('localhost','root','','qpapers');
if(!$con)
die("Connection not established.");

$qname=$aname="";
$qname=$_POST['qpname'];
$aname=$_POST['auth_name'];

$sql = "INSERT INTO reg_qpaper (id, name, auth)
VALUES (NULL, '$qname', '$aname')";
if(!mysqli_query($con,$sql))
echo mysqli_error($con);

$sql2="CREATE TABLE ".$qname." (id INT AUTO_INCREMENT PRIMARY KEY,
qref INT, response INT)";
if(mysqli_query($con,$sql2))
{
$_SESSION['qpname']=$qname;
echo $_SESSION['qpname'];
header("Location: addqref.html");
}
else
echo mysqli_error($con);



?>






10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# MiniProject2019
# miniproj2
This is my second attempt on the project. It uses php for backend and no javascript.

# Important
please import the databases in phpmyadmin and make sure that WAMP server is running before trying to run the website in netbeans.

The databases to be imported are provide in JSON format.
-> qbank.json
-> qpapers.json
21 changes: 21 additions & 0 deletions addqref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>
Add Question Reference
</title>
</head>
<body>
<form action="submitqref.php" method="POST">
Please enter question reference number:<br><br>
<input type="number" name="qref"><br>
<input type="submit" value="Next" formaction="nextqref.php">
<input type="submit" value="Submit" formaction="submitqref.php">
</form>
</body>
</html>
6 changes: 6 additions & 0 deletions destroy_sess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
require'Includes/connector.php';
mysqli_query($qpcon,"UPDATE ".$_SESSION['testname'].' SET response=NULL')or die("delete respone didnt work");
session_destroy();
header("location:index.php");
?>
65 changes: 65 additions & 0 deletions exam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<?php require'Includes/connector.php';
if(!isset($_SESSION['testname']))
{
header("location=index.php");
}
if(!isset($_SESSION['qno']))
{
$_SESSION['qno']=1;
}


$qno=$_SESSION['qno'];
$query1='SELECT qref,response FROM '.$_SESSION['testname'].' WHERE id='.$qno;
$query1res=mysqli_query($qpcon,$query1) or die("sql query didnt work");
$a=mysqli_fetch_assoc($query1res);
$qref= $a['qref'];
$response=$a['response'];
$query2='SELECT content,options FROM qstn WHERE id='.$qref;
$query2result=mysqli_query($con,$query2) or die("sql query2 didnt work");
$arr=mysqli_fetch_assoc($query2result);
$qfile= $arr['content'];
$options=(int)$arr['options'];
//$question=readfile($qfile);
?>
<html>
<head>
<title>
<?php echo $_SESSION['testname'];?>
</title>
<?php require 'Includes/bsplugin.php';?>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-lg-9">
<?php
echo 'Q.no.'.$qno."<br/>";
readfile($qfile);
//echo "question no:".$qno."\nqref".$qref."\ntestname=".$_SESSION['testname'];
?>
</div >
<div class="col-lg-3">
interaction buttons should appear here
<form action="exam.php" method="get">
<?php
for($i=1;$i<=$options;$i++)
{
if($response==$i)
echo '<input type="radio" name="answer" value='.$i.' checked>Option '.$i.'<br/>';
else
echo '<input type="radio" name="answer" value='.$i.' >Option '.$i.'<br/>';
}
?>
<input type="submit" value="Save and Next" formaction="saveQ.php">
<input type="submit" value="nextQ" formaction="nextQ.php">
<input type="submit" value="prevQ" formaction="prevQ.php">
<input type="submit" value="Submit" formaction="submit.php">
</form>
</div>
</div>
</div>
</body>
</html>

165 changes: 28 additions & 137 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,145 +1,36 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
require 'Includes/connector.php';
$available=mysqli_query($qpcon,"SELECT name FROM reg_qpaper") or die("reg command didnt work");

?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<?php require 'Includes/bsplugin.php';?>

<title>Qbank2</title>
</head>
<body>
<?php
require_once 'connect.php';




$uname = $pw = $confirm_pw = "";
$uname_err = $pw_err = $confirm_pw_err = "";


if($_SERVER["REQUEST_METHOD"] == "POST"){


if(empty(trim($_POST["username"]))){
$uname_err = "Please enter a username.";
} else{

$sql = "SELECT id FROM users WHERE username = ?";

if($stmt = mysqli_prepare($link, $sql)){

mysqli_stmt_bind_param($stmt, "s", $param_username);


$param_username = trim($_POST["username"]);


if(mysqli_stmt_execute($stmt)){

mysqli_stmt_store_result($stmt);

if(mysqli_stmt_num_rows($stmt) == 1){
$uname_err = "This username is already taken.";
} else{
$uname = trim($_POST["username"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}


mysqli_stmt_close($stmt);
}


if(empty(trim($_POST["password"]))){
$pw_err = "Please enter a password.";
} elseif(strlen(trim($_POST["password"])) < 6){
$pw_err = "Password must have atleast 6 characters.";
} else{
$pw = trim($_POST["password"]);
}

if(empty(trim($_POST["confirm_password"]))){
$confirm_pw_err = "Please confirm password.";
}
else{
$confirm_pw = trim($_POST["confirm_password"]);
if(empty($pw_err) && ($pw != $confirm_pw)){
$confirm_pw_err = "Password did not match.";
}
}


if(empty($uname_err) && empty($pw_err) && empty($confirm_pw_err)){


$sql = "INSERT INTO users (username, password) VALUES (?, ?)";

if($stmt = mysqli_prepare($link, $sql)){

mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);

$param_username = $uname;
$param_password = password_hash($pw, PASSWORD_DEFAULT);

if(mysqli_stmt_execute($stmt)){

header("location: login.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
}

mysqli_close($link);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">

body{ font: 14px sans-serif; }
h2 {background-color:powderblue; color: grey;}
.wrapper{ width: 350px; padding: 20px; }
</style>
</head>
<body>
<div class="wrapper">
<h2>Sign Up to <b>SHIKSHA</b></h2>
<p>Please fill this form to create an account.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($uname_err)) ? 'has-error' : ''; ?>">
<label>Username</label>
<input type="text" name="username" class="form-control" value="<?php echo $uname; ?>">
<span class="help-block"><?php echo $uname_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($pw_err)) ? 'has-error' : ''; ?>">
<label>Password</label>
<input type="password" name="password" class="form-control" value="<?php echo $pw; ?>">
<span class="help-block"><?php echo $pw_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($confirm_pw_err)) ? 'has-error' : ''; ?>">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_pw; ?>">
<span class="help-block"><?php echo $confirm_pw_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="reset" class="btn btn-default" value="Reset">
</div>
<p>Already have an account? <a href="login.php">Login here</a>.</p>
<?php
include 'Includes/header.php';
?>
<form action="starttest.php" method="get">
<input name="testname2" id="tname" type="text" value="Name of Test"/>
<select name="testname">
<?php for($i= mysqli_num_rows($available);$i>0;$i--)
{
echo '<option>'.mysqli_fetch_assoc($available)['name'].'</option>';
}?>
</select>
<input type="submit" value="Start Test"/><br>
<br>
<a href="qpapernew.html">Click here</a> to create new question paper!
</form>
</div>
</body>
</body>
</html>





9 changes: 9 additions & 0 deletions nextQ.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
require 'Includes/connector.php';
//mysqli_query($qpcon,'UPDATE '.$_SESSION['testname'].' SET response='.$_GET['answer'].' WHERE id='.$_SESSION['qno']);
$_SESSION['qno']+=1;
if($_SESSION['qno']>$_SESSION['max_rows'])
$_SESSION['qno']=1;
header("location:exam.php");
?>

18 changes: 18 additions & 0 deletions nextqref.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

session_start();
$con=mysqli_connect('localhost','root','','qpapers');
if(!$con)
die("Connection not established.");
$qrefval=$_POST['qref'];
$qpname=$_SESSION['qpname'];
echo $qpname;
$sql = "INSERT INTO $qpname (id, qref, response)"
. "VALUES (NULL,'$qrefval',NULL)";
if(mysqli_query($con,$sql))
{
header("Location: addqref.html");
}
else
echo mysqli_error($con);
?>
42 changes: 42 additions & 0 deletions plan.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
starttest.php
{
terms and conditions
button to start test.
}




exam.php
{
get[qno]=question number;
display question
{
get qstn reference from qpaper table
find qstion in qstn table
read file and output
}

change qno buttons
{
redirect to the same page with diff qno
}

record ans
{
record the ans in table
}

there will be a submit button --links to submit.php --submits the name of the qpaper table in post method
}






submit.php
{
check answers and display results
delete table
}
Loading

0 comments on commit cc5b0ee

Please sign in to comment.