Ok so I previously have asked about setting up counter on number of downloads, and I succeeded so thanks to all who helped me out. But now I have another problem and that is to actually update the table with new incremented value.
So what I do is this
Code:
$user_name = "***";
$password = "***";
$database = "s_data";
$server = "***";
$db = mysql_connect($server, $user_name, $password);
$db_counter = mysql_select_db($database, $db_section);
$SQL = "SELECT * FROM `data`";
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result))
{
if(($db_field['section'] == $_POST['section'])&&($db_field['course'] == $_POST['course'])&&($db_field['type'] == $_POST['type'])&&($db_field['name'] == $_POST['file']))
{
$section = $db_field['section'];
$course = $db_field['course'];
$type = $db_field['type'];
$link = $db_field['link'];
$name = $db_field['name'];
$year = $db_field['year'];
$prof = $db_field['prof'];
$rank = $db_field['rank'];
$downloads = $db_field['downloads'];
}
}
$counter = $downloads+1;
UPDATE 'data'
SET `downloads` = $counter
WHERE CONVERT( `data`.`section` USING utf8 ) = $section AND CONVERT( `data`.`course` USING utf8 ) = $course AND CONVERT( `data`.`type` USING utf8 ) = $type AND CONVERT( `data`.`link` USING utf8 ) = $link AND CONVERT( `data`.`name` USING utf8 ) = $name AND `data`.`year` = $year AND CONVERT( `data`.`prof` USING utf8 ) = $prof AND `data`.`rank` = $rank AND `data`.`downloads` = $downloads LIMIT 1 ;
mysql_close($db);
?>
Thank you <br />
Your download will begin in 3 seconds
<meta http-equiv="REFRESH" content="3;url=<?php echo $link; ?>">
Well I get user through 4 pages of selection, in each page he gives me 4 pieces of data which are course section, course code, type of file and then when he clicks on the actual file i know which file he wants from the list
So I search through my database for all those 4 matching items in the while loop, and when I find it I store that data, increment download value and try to update it, but unfrotunately right where it says update I got this erorr
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/***/public_html/database/index5.php
so if anyone can please give me a crash course on how to do update I will be more than happy
Now the sql consists of section s_data which contains my table named data
I read up saying when you use update you have to specify table name, but how will it know that the table named data is located under s_data?
I really do not know how to update sorry for sounding like a noob.
And thanks to all who can help me
__________________
Those who can: learn. Those who can't: teach.
|