Commit acda07e9 authored by Paarth's avatar Paarth

added questions backend

parent 0f54208a
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- version 5.0.3
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Dec 07, 2020 at 06:55 AM
-- Server version: 10.4.13-MariaDB
-- PHP Version: 7.4.8
-- Generation Time: Dec 07, 2020 at 01:18 PM
-- Server version: 10.4.14-MariaDB
-- PHP Version: 7.4.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
......@@ -23,6 +23,24 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Table structure for table `questions`
--
CREATE TABLE `questions` (
`title` varchar(50) NOT NULL,
`username` varchar(50) NOT NULL,
`statement` text NOT NULL,
`tc1` text NOT NULL,
`out1` text NOT NULL,
`tc2` text NOT NULL,
`out2` text NOT NULL,
`stime` datetime NOT NULL,
`etime` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
......@@ -41,15 +59,14 @@ CREATE TABLE `users` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `users`
-- Indexes for dumped tables
--
INSERT INTO `users` (`id`, `username`, `name`, `password`, `email`, `img_url`, `n_attempts`, `correct_timeline`, `rating`, `n_files`) VALUES
(26, 'adarsh', 'adarsh', '$2y$10$PT.s983qY0EjVx2w1JBRT.y3XO3kd4wnWIng7t4.udLeWAizHDfDi', 'a@g.com', 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg', 0, '[]', 0, 0);
--
-- Indexes for dumped tables
-- Indexes for table `questions`
--
ALTER TABLE `questions`
ADD PRIMARY KEY (`title`);
--
-- Indexes for table `users`
......@@ -70,4 +87,4 @@ COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
\ No newline at end of file
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<?php
include_once("database.php");
if($_SERVER['REQUEST_METHOD'])){
$sql1 = "SELECT Now()";
$currtime = $mysqli->query($sql1);
$sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
$data = [];
if($result = mysqli->query($sql2)){
while($row = mysql_fetch_assoc($request)){
array_push($data,$row);
}
echo json_encode($data);
}
else{
http_response_code(404);
}
}
?>
\ No newline at end of file
<?php
include_once("database.php");
$postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)){
$request = json_decode($postData);
$title = trim($request->title);
$username = trim($request->username); //string
$statement = trim($request->statement); //string
$tc1 = trim($request->tc1_inp);
$out1 = trim($request->tc1_out);
$tc2 = trim($request->tc2_inp);
$out2 = trim($request->tc2_out);
$stime = trim($request->start_time); //string
$etime = trim($request->end_time)
$sql = "INSERT INTO questions($title,$username,$statement,$tc1,$out1,$tc2,$out2,$stime,$etime)";
if($result = $mysqli->query($sql)){
$msg = "question uploaded";
echo json_encode($msg);
}
else{
$msg = "title already exists";
echo json_encode($msg);
}
}
?>
\ No newline at end of file
......@@ -29,3 +29,4 @@ if (isset($postData) && !empty($postData)) {
echo "mysqli_error($mysqli)";
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment