need a help on this query code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    need a help on this query code

    Dear friends, need to fix following code.

    when i execute following sql code views count is not updating??


    require('db.php');
    $id=$_REQUEST['id'];
    $query = "update files SET views = views+1 where id ='".$id."'";
    $query = "SELECT * from files where id='".$id."'";
    $result = mysqli_query($con, $query) or die ( mysqli_error());
    $row = mysqli_fetch_assoc($result);


    #2
    If I PUT $query = update code bellow the $query = "SELECT code views count will updated but $row File results will not show. please help.

    Comment


      #3
      You are overwriting the variable $query with a new variable.
      So you need to use the query before you set it to a new variable eg:
      Code:
      require('db.php');
      $id = $_REQUEST['id'];
      $query = "update files SET views = views+1 where id ='".$id."'";
      $update = mysqli_query($con, $query) or die ( mysqli_error());
      $query = "SELECT * from files where id='".$id."'";
      $result = mysqli_query($con, $query) or die ( mysqli_error());
      $row = mysqli_fetch_assoc($result);
      or alternatively to use a single call to the database use:
      Code:
      require('db.php');
      $id = $_REQUEST['id'];
      $query = "update files SET views = views+1 where id ='".$id."';";  
      $query .= "SELECT * from files where id='".$id."'";   
      $result = mysqli_query($con, $query) or die ( mysqli_error());
      $row = mysqli_fetch_assoc($result);

      Comment


        #4
        Brother your solution is working 100% thank you soo much..

        Comment


          #5
          another problem need to be fixed on my script could you please give me some help on it also bro??

          i'm working on an autoindex mp3 downloading site script, once song is GET_($id) @ download page I need to show $row['artist'] related mp3 files from my db. could you give me a solution for this also???

          Comment

          Working...
          X