Commit f97fa5e5 authored by Paarth's avatar Paarth

reorganised database and subsequent modifications

parent 1fc714c7
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- version 5.0.3
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Oct 28, 2020 at 02:33 AM
-- Generation Time: Dec 06, 2020 at 03:21 PM
-- Server version: 10.4.14-MariaDB
-- PHP Version: 7.4.10
-- PHP Version: 7.4.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
......@@ -24,49 +24,48 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Table structure for table `users`
-- Table structure for table `userdata`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
CREATE TABLE `userdata` (
`username` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`img_url` text DEFAULT 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg',
`n_attempts` int(11) NOT NULL DEFAULT 0,
`correct_timeline` text DEFAULT '[]',
`rating` int(11) NOT NULL DEFAULT 0
`n_files` int(11) DEFAULT NULL,
`img_url` text DEFAULT NULL,
`n_attempts` int(11) DEFAULT NULL,
`correct_timeline` text DEFAULT NULL,
`rating` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Dumping data for table `users`
-- Table structure for table `users`
--
INSERT INTO `users` (`id`, `username`, `name`, `password`, `email`, `img_url`, `n_attempts`, `correct_timeline`, `rating`) VALUES
(24, 'ayushjangir', 'Ayush Jangir', '$2y$10$VXSfup83ux6QKRIt4LPPZ.lAz7GbvN6yT/Tk5LH5eNKk1oussrwHm', 'jangirayush59@gmail.com', 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg', 150, '[0,1,1,0,1,0,1,1,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,1,1,0,0,0,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,1,1,0,1,1,0,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,1,0,1,0,1,1,1,1]', 1278);
CREATE TABLE `users` (
`username` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
-- Indexes for table `userdata`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
ALTER TABLE `userdata`
ADD PRIMARY KEY (`username`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
-- Indexes for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
ADD PRIMARY KEY (`username`);
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 */;
......@@ -15,27 +15,29 @@ if (isset($postData) && !empty($postData)) {
$msg = "file already exists";
clearstatcache();
echo json_encode($msg);
} else {
// $sql1 = "SELECT n_files from userdata where username = $username";
// $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
// $result = mysqli_query($mysqli, $sql1);
// if($result == 10){
// $msg = "maximum limit(10) exceeded";
// echo json_encode($msg);
// }
// else{
// if($result = mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
}
else {
$sql1 = "SELECT n_files from userdata where username = $username";
$sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
$result = mysqli_query($mysqli, $sql1);
if($result == 10){
$msg = "maximum limit(10) reached";
echo json_encode($msg);
}
else{
if($result = mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
$msg = "file successfully uploaded";
clearstatcache();
echo json_encode($msg);
// }
// else{
// http_response_code(404);
// }
$msg = "file successfully uploaded";
clearstatcache();
echo json_encode($msg);
}
else{
http_response_code(404);
}
}
}
......
......@@ -4,8 +4,8 @@ $postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)) {
$request = json_decode($postData);
// $username = trim($request->username);
$dir = trim($request->dir);
$path = trim($request->currdir) . '/' . $dir;
$dirname = trim($request->dirname);
$path = trim($request->currdir) . '/' . $dirname;
if(file_exists($path)) {
$msg = "directory already exists";
clearstatcache();
......
......@@ -20,7 +20,8 @@ if (isset($postData) && !empty($postData)) {
];
mkdir('../users/' . $authData['username']);
$sql1 = "INSERT INTO userdata(username,n_files,img_url,n_attempts,correct_timeline,rating) VALUES ('$username',0,'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg',0,'[]',0)";
$mysqli->query($sql1);
echo json_encode($authData);
}
......
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