Commit f97fa5e5 authored by Paarth's avatar Paarth

reorganised database and subsequent modifications

parent 1fc714c7
-- phpMyAdmin SQL Dump -- phpMyAdmin SQL Dump
-- version 5.0.2 -- version 5.0.3
-- https://www.phpmyadmin.net/ -- https://www.phpmyadmin.net/
-- --
-- Host: localhost -- 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 -- Server version: 10.4.14-MariaDB
-- PHP Version: 7.4.10 -- PHP Version: 7.4.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION; START TRANSACTION;
...@@ -24,47 +24,46 @@ SET time_zone = "+00:00"; ...@@ -24,47 +24,46 @@ SET time_zone = "+00:00";
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `users` -- Table structure for table `userdata`
-- --
CREATE TABLE `users` ( CREATE TABLE `userdata` (
`id` int(11) NOT NULL,
`username` varchar(50) NOT NULL, `username` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL, `n_files` int(11) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL, `img_url` text DEFAULT NULL,
`email` varchar(255) DEFAULT NULL, `n_attempts` int(11) DEFAULT NULL,
`img_url` text DEFAULT 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg', `correct_timeline` text DEFAULT NULL,
`n_attempts` int(11) NOT NULL DEFAULT 0, `rating` int(11) DEFAULT NULL
`correct_timeline` text DEFAULT '[]',
`rating` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) 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 CREATE TABLE `users` (
(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); `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 dumped tables
-- --
-- --
-- Indexes for table `users` -- Indexes for table `userdata`
-- --
ALTER TABLE `users` ALTER TABLE `userdata`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`username`);
-- --
-- AUTO_INCREMENT for dumped tables -- Indexes for table `users`
--
--
-- AUTO_INCREMENT for table `users`
-- --
ALTER TABLE `users` ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25; ADD PRIMARY KEY (`username`);
COMMIT; COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
......
...@@ -15,16 +15,17 @@ if (isset($postData) && !empty($postData)) { ...@@ -15,16 +15,17 @@ if (isset($postData) && !empty($postData)) {
$msg = "file already exists"; $msg = "file already exists";
clearstatcache(); clearstatcache();
echo json_encode($msg); echo json_encode($msg);
} else { }
// $sql1 = "SELECT n_files from userdata where username = $username"; else {
// $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username "; $sql1 = "SELECT n_files from userdata where username = $username";
// $result = mysqli_query($mysqli, $sql1); $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
// if($result == 10){ $result = mysqli_query($mysqli, $sql1);
// $msg = "maximum limit(10) exceeded"; if($result == 10){
// echo json_encode($msg); $msg = "maximum limit(10) reached";
// } echo json_encode($msg);
// else{ }
// if($result = mysqli_query($mysqli, $sql2)) { else{
if($result = mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w"); $myfile = fopen($path, "w");
fwrite($myfile, $data); fwrite($myfile, $data);
fclose($myfile); fclose($myfile);
...@@ -32,10 +33,11 @@ if (isset($postData) && !empty($postData)) { ...@@ -32,10 +33,11 @@ if (isset($postData) && !empty($postData)) {
$msg = "file successfully uploaded"; $msg = "file successfully uploaded";
clearstatcache(); clearstatcache();
echo json_encode($msg); echo json_encode($msg);
// } }
// else{ else{
// http_response_code(404); http_response_code(404);
// } }
}
} }
......
...@@ -4,8 +4,8 @@ $postData = file_get_contents("php://input"); ...@@ -4,8 +4,8 @@ $postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)) { if(isset($postData) && !empty($postData)) {
$request = json_decode($postData); $request = json_decode($postData);
// $username = trim($request->username); // $username = trim($request->username);
$dir = trim($request->dir); $dirname = trim($request->dirname);
$path = trim($request->currdir) . '/' . $dir; $path = trim($request->currdir) . '/' . $dirname;
if(file_exists($path)) { if(file_exists($path)) {
$msg = "directory already exists"; $msg = "directory already exists";
clearstatcache(); clearstatcache();
......
...@@ -20,7 +20,8 @@ if (isset($postData) && !empty($postData)) { ...@@ -20,7 +20,8 @@ if (isset($postData) && !empty($postData)) {
]; ];
mkdir('../users/' . $authData['username']); 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); 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