diff --git a/Tatia_Tutashvili/app.css b/Tatia_Tutashvili/app.css new file mode 100644 index 0000000..cf033b3 --- /dev/null +++ b/Tatia_Tutashvili/app.css @@ -0,0 +1,20 @@ +body{ + padding:50px; +} +form{ + display:flex; + justify-content: center; + align-items: center; +} + +.container{ + display: flex; + justify-content: flex-start; + text-align: inherit; + align-items: center; + width: 70%; +} +.pic{ + height:50px; + width:50px; +} \ No newline at end of file diff --git a/Tatia_Tutashvili/index.php b/Tatia_Tutashvili/index.php new file mode 100644 index 0000000..e06a5d8 --- /dev/null +++ b/Tatia_Tutashvili/index.php @@ -0,0 +1,128 @@ +setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); +$statement = $pdo -> prepare('SELECT * FROM profiles'); +$statement ->execute(); +$profiles = $statement->fetchAll(PDO::FETCH_ASSOC); + +$errors= []; +$name= ''; +$surname = ''; + +if($_SERVER['REQUEST_METHOD'] === 'POST') +{ $name =$_POST['name']; +$surname =$_POST['surname']; +$image =$_FILES['image'] ?? null; +$imagePath = ''; + +if(!is_dir('images')) +{ + mkdir('images'); +} +if($image) +{ + $imagePath = 'images/'.randomString(8).'/'.$image['name']; + mkdir(dirname($imagePath)); + move_uploaded_file($image['tmp_name'], $imagePath); +} +if(!$surname ) +{ + $errors[] = 'Surname is required'; + +} +if(!$name) +{ + $errors[] = 'Product price is required'; +} + +if(empty($errors)) +{ + $statement = $pdo->prepare("INSERT INTO profiles(image,name,surname) + VALUES(:image,:name,:surname)"); + $statement->bindValue(':image',$imagePath); + $statement->bindValue(':name',$name); + $statement->bindValue(':surname',$surname); + + + $statement->execute(); + header('Location: index.php'); + } + +} + +function randomString($n) +{ + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $str = ''; + for($i=0; $i<$n; $i++) + { + $index = rand(0, strlen($characters)-1); + $str.= $characters[$index]; + } + + return $str; +} +?> + + + + + + + Bootstrap demo + + + + + +
+ +
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ + + + + + + + + + + $profile) : ?> + + + + + + + + +
#ImageNameSurname
+ + <?php echo $profile['name'] ?> + +
+ + + \ No newline at end of file