I want help in mysql please read this

Started on the old forum in June 2011 · view the original in the archive · old links redirect here

11 replies · 692 views · started 15 years ago · 1 min read

6 participants
jayasrilanka Junior · 12 posts #1

I have a download page in my wapsite and each file details has enterd to a mysql database, i want to show how many times downloaded each file, its UPDATE table SET +1 Like Something arround it, But i dont know it correctly please someone help me pls

firemax Developer · 221 posts #2

If the files table name 'files' , downloads counter column name 'downloads' and auto increment file id column name 'id' that you can use the following sql command. $id is the file id of user going to download.

UPDATE files SET downloads=downloads+1 WHERE id=$id

External image (may be gone) Free Mobile Web Scripts by me: Free Youtube Downloader, Tweets Reader, Facebook Wall Posts Reader PHP Tutorials: [How to Secure Your PHP Script (PHP SECURITY)](http://coding-talk.com/f14/how-to-secure-you…

jayasrilanka Junior · 12 posts #3

Please give me full code

Please firemax i want full code, my table name is 'example' and couner column name is 'hits' and i want update hits by my file title, not increamnt id.. Please can u give me full code.. With the sql connection

firemax Developer · 221 posts #4

Ok, check this one

<?php
$mysqlserver = 'localhost';
$database = 'DTABASENAME';
$db_user = 'USERNAME';
$db_pass = 'PASSWORD';

$link = mysql_connect($mysqlserver, $db_user, $db_pass) or die('Could not connect to Database');
$db_id = mysql_select_db($database, $link) or die('Could not select Database');

$title = "YOUR-FILE-TITLE";

mysql_query("UPDATE `example` SET `hits`=`hits`+1 WHERE `title`=$title");

External image (may be gone) Free Mobile Web Scripts by me: Free Youtube Downloader, Tweets Reader, Facebook Wall Posts Reader PHP Tutorials: [How to Secure Your PHP Script (PHP SECURITY)](http://coding-talk.com/f14/how-to-secure-you…

jayasrilanka Junior · 12 posts #5

Its not wrking

Its not working.. May be i dnt knw how to use it correctly.. If someone can explain more.. May be it has a column error what i have created.. Saddddddd

kei_ki7 Senior · 431 posts #6

Post your code, many of here can help you.

Did I help you? You can help me too Your donations will help me finance my studies.

jayasrilanka Junior · 12 posts #9

This is the Code. Please help me to correct it..

<?php mysql_connect("localhost", "jayasri6_dlc", "jaya") or die(mysql_error());mysql_select_db("jayasri6_dlc") or die(mysql_error()); $id = $_GET['file']; $result = mysql_query("SELECT * FROM example WHERE title='$id'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $chit = $row['hits']; echo "Name:"; echo $row['title']; echo " "; echo "Artist: "; echo $row['artist']; echo " "; echo "Size:"; echo $row['size']; echo " "; echo "Downloads:"; echo $row['hits']; echo ""; echo " Date:"; echo $row['date']; echo " <a href='"; echo $row['url']; echo "'>[DOWNLOAD MP3]</a> "; }; echo " Other Options: Share This: "; ?>[&t=<?php echo $_GET['file']; ?>">![](http://jayasrilanka.wen.ru/images/s_fb.gif)](http://www.facebook.com/sharer.php?u=http://dl.jayasrilanka.net/?file=<?php%20echo%20$_GET[) | [:http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>">![](http://jayasrilanka.wen.ru/images/s_tw.gif)](http://twitter.com/home?status=<?php%20echo%20$_GET[)

Share Url:

<input type="text" size="12" value="http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>" />
Ponick Developer · 216 posts #10

jayasrilanka wrote:

<?php mysql_connect("localhost", "jayasri6_dlc", "jaya") or die(mysql_error());mysql_select_db("jayasri6_dlc") or die(mysql_error()); $id = $_GET['file']; $result = mysql_query("SELECT * FROM example WHERE title='$id'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $chit = $row['hits']; echo "Name:"; echo $row['title']; echo " "; echo "Artist: "; echo $row['artist']; echo " "; echo "Size:"; echo $row['size']; echo " "; echo "Downloads:"; echo $row['hits']; echo ""; echo " Date:"; echo $row['date']; echo " <a href='"; echo $row['url']; echo "'>[DOWNLOAD MP3]</a> "; }; echo " Other Options: Share This: "; ?>[&t=<?php echo $_GET['file']; ?>">![](http://jayasrilanka.wen.ru/images/s_fb.gif)](http://www.facebook.com/sharer.php?u=http://dl.jayasrilanka.net/?file=<?php%20echo%20$_GET[) | [:http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>">![](http://jayasrilanka.wen.ru/images/s_tw.gif)](http://twitter.com/home?status=<?php%20echo%20$_GET[)

Share Url:

<input type="text" size="12" value="http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>" />

change your code like this:

<?php
session_start();

 mysql_connect("localhost", "jayasri6_dlc", "jaya") or die(mysql_error());mysql_select_db("jayasri6_dlc") or die(mysql_error());

$id = $_GET['file'];
$result = mysql_query("SELECT * FROM example WHERE title='$id'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$chit = $row['hits'];
echo "<div style=\"text-align:left\"><small style=\"color:red;text-align:left\">Name:</small><small style=\"color:green;\">"; echo $row['title']; echo "</small><br/>";
echo "<small style=\"color:red;text-align:left\">Artist: </small><small style=\"color:green;\">"; echo $row['artist']; echo "</small><br/>";
echo "<small style=\"color:red;\">Size:</small><small style=\"color:green;\">";
echo $row['size'];
echo "</small><br />";
echo "<small style=\"color:red;\">Downloads:</small><small style=\"color:green;\">";
echo $row['hits'];
echo "</small>";
echo "<small style=\"color:red;\"><br/>Date:</small><small style=\"color:green;\">";
echo $row['date'];
echo "</small></div><div style=\"text-align=:center\"><br/><a href='";

$_SESSION['link']=$row['url'];

echo "load.php?file=$id"; echo "'>[DOWNLOAD MP3]</a><br /></div>";
};
echo "<div style=\"text-align:left;\"><br /><span style=\"color:red\">Other Options:
</span><br /><small style=\"color:green\">Share This:
</small></div>
<div style=\"text-align:center;\">"; ?><a href="http://www.facebook.com/sharer.php?u=http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>&t=<?php echo $_GET['file']; ?>"><img src="http://jayasrilanka.wen.ru/images/s_fb.gif" alt="fb"/></a> | <a href="http://twitter.com/home?status=<?php echo $_GET['file']; ?>:http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>"><img src="http://jayasrilanka.wen.ru/images/s_tw.gif" alt="twit"/></a><br /><div style="text-align:left;"><br /><span style="color:red">Share Url:
</span><br /><input type="text" size="12" value="http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>" />

make load.php with this code

<?php
session_start();
$id = $_GET['file'];
$link=$_SESSION['link'];
 mysql_connect("localhost", "jayasri6_dlc", "jaya") or die(mysql_error());mysql_select_db("jayasri6_dlc") or die(mysql_error());

$done=mysql_query("UPDATE example SET hits=hits+1 WHERE title='".$id."'");
if($done)
{
header("Location: $link");
  exit();
}

?>
/* I don't know everything hehe */

Find me on facebook

jayasrilanka Junior · 12 posts #11

Displaying Error

Its displaying error: Download ape_game_thibena.mp3Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jayasri6/public_html/dl/index.php:2) in/home/jayasri6/public_html/dl/index.phpon line6

Ponick Developer · 216 posts #12

jayasrilanka wrote: Its displaying error: Download ape_game_thibena.mp3Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jayasri6/public_html/dl/index.php:2) in/home/jayasri6/public_html/dl/index.phpon line6

then modify it :

<?php
 
mysql_connect("localhost", "jayasri6_dlc", "jaya") or die(mysql_error());mysql_select_db("jayasri6_dlc") or die(mysql_error());

$id = $_GET['file'];
$result = mysql_query("SELECT * FROM example WHERE title='$id'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$chit = $row['hits'];
echo "<div style=\"text-align:left\"><small style=\"color:red;text-align:left\">Name:</small><small style=\"color:green;\">"; echo $row['title']; echo "</small><br/>";
echo "<small style=\"color:red;text-align:left\">Artist: </small><small style=\"color:green;\">"; echo $row['artist']; echo "</small><br/>";
echo "<small style=\"color:red;\">Size:</small><small style=\"color:green;\">";
echo $row['size'];
echo "</small><br />";
echo "<small style=\"color:red;\">Downloads:</small><small style=\"color:green;\">";
echo $row['hits'];
echo "</small>";
echo "<small style=\"color:red;\"><br/>Date:</small><small style=\"color:green;\">";
echo $row['date'];
echo "</small></div><div style=\"text-align=:center\"><br/><a href='";

echo "load.php?file=$id"; echo "'>[DOWNLOAD MP3]</a><br /></div>";
};
echo "<div style=\"text-align:left;\"><br /><span style=\"color:red\">Other Options:
</span><br /><small style=\"color:green\">Share This:
</small></div>
<div style=\"text-align:center;\">"; ?><a href="http://www.facebook.com/sharer.php?u=http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>&t=<?php echo $_GET['file']; ?>"><img src="http://jayasrilanka.wen.ru/images/s_fb.gif" alt="fb"/></a> | <a href="http://twitter.com/home?status=<?php echo $_GET['file']; ?>:http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>"><img src="http://jayasrilanka.wen.ru/images/s_tw.gif" alt="twit"/></a><br /><div style="text-align:left;"><br /><span style="color:red">Share Url:
</span><br /><input type="text" size="12" value="http://dl.jayasrilanka.net/?file=<?php echo $_GET['file']; ?>" />

load.php

<?php

 mysql_connect("localhost", "jayasri6_dlc", "jaya") or die(mysql_error());mysql_select_db("jayasri6_dlc") or die(mysql_error());
 $id = $_GET['file'];
 $link=mysql_fetch_array(mysql_query("SELECT url FROM example WHERE title='".$id."'"));
 
$done=mysql_query("UPDATE example SET hits=hits+1 WHERE title='".$id."'");
if($done)
{
header("Location: $link[0]");
  exit();
}

?>
/* I don't know everything hehe */

Find me on facebook

Write your reply now; next you create a free account (or sign in) and it is posted right away. 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