Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ?>
- <!doctype html>
- <html>
- <head>
- <title>Zend</title>
- <link rel="stylesheet" type="text/css" href="style.css" />
- <meta charset="UTF-8" />
- <meta name="author" content="Lucie Opravilová" />
- <meta name="keywords" content="inf, zend, css, html" />
- <meta name="description" content="Zápočtová úloha do INFS" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
- <script src="js/arrow.js"></script>
- <script src="js/autocomplete.js"></script>
- </head>
- <body>
- <div id="stranka">
- <?php include 'php/header.php';?>
- <main id="panely">
- <article id="levy-panel">
- <?php if(isset($_SESSION['login'])){ ?>
- <h3> Edit profile <br></h3>
- <form autocomplete="on" method="post" enctype="multipart/form-data">
- <?php
- if(isset($_POST['submit-user-account'])) {
- function upload_picture($picture)
- {
- $target_dir = "localhost/obrazky/avatars/";
- $target_file = $target_dir . basename($picture["name"]);
- $fileType = pathinfo($target_file,PATHINFO_EXTENSION);
- $check = getimagesize($picture["tmp_name"]);
- $upload=true;
- if (!$check){
- echo "not a pic.";
- $upload=false;
- }
- if ($upload){
- $newfilename=0;
- $tmp = preg_match('/\.[^\.]+$/i',$picture["name"],$ext);
- while(file_exists("obrazky/avatars/" . $newfilename . $ext[0]))
- {
- $newfilename = 1 + $newfilename;
- }
- if (move_uploaded_file($picture["tmp_name"], "obrazky/avatars/" . $newfilename . $ext[0])){
- return $target_dir . $newfilename . $ext[0];
- } else {
- echo "Sorry, there was an error uploading your file.";
- }
- }
- return null;
- }
- $host="localhost";
- $db_username="root";
- $db_password="root";
- $db_name="zend_db";
- $tbl_name="user";
- $connection = mysqli_connect("$host", "$db_username", "$db_password");
- mysqli_select_db($connection, $db_name);
- if (!$connection) {
- die('Could not connect: ' . mysqli_error());
- }
- $user_id=false;
- if(isset($_SESSION['login'])){
- $usr_name=$_SESSION['login'];
- $sql="SELECT user_id FROM user WHERE username='$usr_name'";
- $result=mysqli_query($connection,$sql);
- $row = mysqli_fetch_array($result);
- $user_id=$row['user_id'];
- }
- if ($user_id !=false){
- $firstN =$_POST['firstname'];
- $secondN=$_POST['secondname'];
- $bio=$_POST['about'];
- $email=$_POST['email'];
- $image=$_FILES['avatar'];
- $image=upload_picture($image);
- /*$date=$_POST['post-date'];*/
- $sql="UPDATE user SET first_name='$firstN', second_name='$secondN', avatar_url='$image', about='$bio', email='$email' WHERE user_id='$user_id'";
- $result=mysqli_query($connection,$sql);
- if (!$result){ ?>
- <label class="label-chyba" for="username"> <h1> Sorry, there was an error uploading your post!</h1> </label> <?php
- } else { ?>
- <label class="label-chyba" for="username"> <h1> OK</h1> </label> <?php
- mysqli_close($connection);
- }
- //
- }
- }
- ?>
- <fieldset class="login-form">
- <label for="firstname"> First name: </label>
- <input type="text" required="required" name="firstname" value="<?php echo $firstN; ?> ">
- </fieldset>
- <fieldset class="login-form">
- <label for="secondname"> Second name: </label>
- <input type="text" required="required" name="secondname" >
- </fieldset>
- <fieldset class="login-form">
- <label for="avatar"> Avatar: </label>
- <input type="file" required="required" name="avatar" >
- </fieldset>
- <fieldset class="login-form">
- <label for="email"> Email: </label>
- <input type="email" required="required" name="email" >
- </fieldset>
- <fieldset class="login-form">
- <label for="about"> About me: </label>
- <textarea name="about" autofocus required wrap="soft"> </textarea>
- </fieldset>
- <fieldset class="login-form">
- <input class="read-more" type="submit" value="Change" name="submit-user-account" />
- </fieldset>
- </form>
- <?php }?>
- </article>
- <aside id="pravy-panel">
- <?php include 'php/aside-small.php';?>
- </aside>
- <div class="clearfix"></div>
- </main>
- <footer>
- <?php include 'php/footer.php'; ?>
- </footer>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement