Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2.     include("connect.php");
  3.     include("functions.php");
  4.  
  5.            
  6.             if(isset($_POST['id'])){
  7.             $end_user=$_SESSION['email'];
  8.            
  9.             $sql="SELECT * FROM users WHERE email='$end_user'";
  10.             $rs=mysqli_query($con,$sql);
  11.             $row=mysqli_fetch_array($rs);
  12.             $id_user=$row[0];
  13.             $nsql="SELECT id FROM stickies WHERE id_user='$id_user'";
  14.             $nrs=mysqli_query($con,$nsql);
  15.             $nrow=mysqli_fetch_array($nrs);
  16.             //$stick=$nrow[0];
  17.             $id_stick = $_POST['id'];
  18.             $top = trim($_POST['top']);
  19.             $left = trim($_POST['left']);
  20.             $text = trim($_POST['text']);          
  21.             if($id_user && $id_stick && $top && $left && $text){
  22.                 for($i = 0;$i < count($nrow);$i++){
  23.                    
  24.                     $nsql="SELECT id FROM stickies WHERE id_user='$id_user'";
  25.                     $nrs=mysqli_query($con,$nsql);
  26.                     $nrow=mysqli_fetch_array($nrs);
  27.                     if($nrow[$i]==$_POST['id']){
  28.                         $query = "UPDATE stickies SET top = '$top', tLeft = '$left', text = '$text' WHERE id = '$id_stick'";
  29.                         mysqli_query($con,$query);
  30.                                         }
  31.  
  32.                     else {
  33.                         $query = "INSERT INTO stickies(id,top,tLeft,text,id_user) VALUES('$id_stick','$top','$left','$text','$id_user')";
  34.                         mysqli_query($con,$query);
  35.                         }
  36.  
  37.                                                 }
  38.                                                                 }
  39.            
  40.             echo $nrow[0];
  41.             //echo $id_user;
  42.             }
  43.             // if(isset($_POST['text']) && $_POST['delete']){
  44.             //  $query = "DELETE FROM 'stickies' WHERE 'text' = '$text'";
  45.             //  mysqli_query($con,$query);
  46.             //  echo 'for ajax';
  47.             // }
  48.            
  49.        
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement