Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 6.73 KB | None | 0 0
  1.  
  2. <?php
  3. session_start();
  4. ?>
  5.  
  6. <!doctype html>
  7. <html>
  8. <head>
  9.     <title>Zend</title>
  10.     <link rel="stylesheet" type="text/css" href="style.css" />
  11.     <meta charset="UTF-8" />
  12.     <meta name="author" content="Lucie Opravilová" />
  13.     <meta name="keywords" content="inf, zend, css, html" />
  14.     <meta name="description" content="Zápočtová úloha do INFS" />
  15.    
  16.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  17.    
  18.     <script src="js/arrow.js"></script>
  19.     <script src="js/autocomplete.js"></script>
  20.    
  21. </head>
  22.  
  23. <body>    
  24.     <div id="stranka">
  25.         <?php include 'php/header.php';?>
  26.        
  27.         <main id="panely">
  28.             <article id="levy-panel">
  29.                
  30.             <?php if(isset($_SESSION['login'])){ ?>
  31.                 <h3> Edit profile <br></h3>
  32.                
  33.                 <form autocomplete="on" method="post" enctype="multipart/form-data">
  34.                    
  35.                     <?php
  36.                    if(isset($_POST['submit-user-account'])) {
  37.                        function upload_picture($picture)
  38.                        {
  39.                            $target_dir = "localhost/obrazky/avatars/";
  40.                            $target_file = $target_dir . basename($picture["name"]);
  41.  
  42.                            $fileType = pathinfo($target_file,PATHINFO_EXTENSION);
  43.                            $check = getimagesize($picture["tmp_name"]);
  44.  
  45.                            $upload=true;
  46.                            if (!$check){
  47.  
  48.                                echo "not a pic.";
  49.                                $upload=false;
  50.                            }
  51.  
  52.  
  53.                            if ($upload){
  54.                                $newfilename=0;            
  55.                                $tmp = preg_match('/\.[^\.]+$/i',$picture["name"],$ext);            
  56.  
  57.  
  58.                                while(file_exists("obrazky/avatars/" . $newfilename . $ext[0]))
  59.                                {                              
  60.                                    $newfilename = 1 + $newfilename;
  61.                                }  
  62.  
  63.                                if (move_uploaded_file($picture["tmp_name"], "obrazky/avatars/" . $newfilename . $ext[0])){
  64.                                    return $target_dir . $newfilename . $ext[0];
  65.                                }   else {
  66.                                    echo "Sorry, there was an error uploading your file.";
  67.                                }
  68.                            }
  69.                            return null;
  70.                        }
  71.                        
  72.                        $host="localhost";
  73.                        $db_username="root";
  74.                        $db_password="root";
  75.                        $db_name="zend_db";
  76.                        $tbl_name="user";
  77.  
  78.                        $connection = mysqli_connect("$host", "$db_username", "$db_password");
  79.                        mysqli_select_db($connection, $db_name);
  80.  
  81.                        if (!$connection) {
  82.                            die('Could not connect: ' . mysqli_error());
  83.                        }
  84.  
  85.                        $user_id=false;
  86.                        if(isset($_SESSION['login'])){
  87.                            $usr_name=$_SESSION['login'];
  88.                            $sql="SELECT user_id FROM user WHERE username='$usr_name'";
  89.                            $result=mysqli_query($connection,$sql);
  90.                            $row = mysqli_fetch_array($result);
  91.                            $user_id=$row['user_id'];
  92.                        }
  93.  
  94.                        if ($user_id !=false){
  95.                            $firstN =$_POST['firstname'];
  96.                            $secondN=$_POST['secondname'];
  97.                            $bio=$_POST['about'];
  98.                            $email=$_POST['email'];
  99.                            $image=$_FILES['avatar'];
  100.                            $image=upload_picture($image);
  101.  
  102.                            /*$date=$_POST['post-date'];*/
  103.  
  104.                            $sql="UPDATE user SET first_name='$firstN', second_name='$secondN', avatar_url='$image', about='$bio', email='$email' WHERE user_id='$user_id'";
  105.  
  106.                            $result=mysqli_query($connection,$sql);
  107.                            if (!$result){ ?>
  108.                                 <label class="label-chyba" for="username"> <h1> Sorry, there was an error uploading your post!</h1> </label> <?php
  109.                            } else { ?>
  110.                                 <label class="label-chyba" for="username"> <h1> OK</h1> </label> <?php  
  111.                                mysqli_close($connection);
  112.                            }
  113.  
  114.                            //
  115.                        }
  116.                        }
  117.                    ?>
  118.                    
  119.                     <fieldset class="login-form">
  120.                         <label for="firstname"> First name: </label>
  121.                         <input type="text" required="required" name="firstname" value="<?php echo $firstN; ?> ">
  122.                     </fieldset>
  123.                    
  124.                     <fieldset class="login-form">
  125.                         <label for="secondname"> Second name: </label>
  126.                         <input type="text" required="required" name="secondname" >
  127.                     </fieldset>
  128.                    
  129.                     <fieldset class="login-form">
  130.                         <label for="avatar"> Avatar: </label>
  131.                         <input type="file" required="required" name="avatar" >
  132.                     </fieldset>
  133.                    
  134.                     <fieldset class="login-form">
  135.                         <label for="email"> Email: </label>
  136.                         <input type="email" required="required" name="email" >
  137.                     </fieldset>
  138.                    
  139.                     <fieldset class="login-form">
  140.                         <label for="about"> About me: </label>
  141.                         <textarea name="about" autofocus required wrap="soft">  </textarea>
  142.                     </fieldset>
  143.                    
  144.                     <fieldset class="login-form">
  145.                         <input class="read-more" type="submit" value="Change" name="submit-user-account" />
  146.                     </fieldset>
  147.  
  148.                 </form>
  149.              <?php }?>
  150.                
  151.             </article>
  152.            
  153.             <aside id="pravy-panel">
  154.                 <?php include 'php/aside-small.php';?>
  155.             </aside>
  156.            
  157.             <div class="clearfix"></div>
  158.         </main>
  159.        
  160.         <footer>
  161.             <?php include 'php/footer.php'; ?>
  162.         </footer>
  163.     </div>
  164. </body>    
  165. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement