need a help on this query code

Started on the old forum in October 2020 · view the original in the archive · old links redirect here

4 replies · 53 views · started 6 years ago · 1 min read

2 participants
ayesham Developer · 69 posts #1

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);

ayesham Developer · 69 posts #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.

something else Fellow · 2,296 posts #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:

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:

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);
ayesham Developer · 69 posts #4

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

ayesham Developer · 69 posts #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???

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close