Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How does update work?
Old 01-06-2010, 11:40 PM How does update work?
Average Talker

Posts: 27
Trades: 0
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.
Cinatas is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-07-2010, 10:23 AM Re: How does update work?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
because this
Code:
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 ;
Should be a string variable to be used in a query.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-07-2010, 10:25 AM Re: How does update work?
Average Talker

Posts: 27
Trades: 0
So how do I use it as a string in a query?
Am I supposed to create a varibale like

Code:
$stringvar = 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 ;
__________________
Those who can: learn. Those who can't: teach.

Last edited by Cinatas; 01-07-2010 at 10:27 AM..
Cinatas is offline
Reply With Quote
View Public Profile
 
Old 01-07-2010, 10:28 AM Re: How does update work?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Well, with the addition of quote marks. Yes
Quote:
$stringvar = " 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 ;"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-07-2010, 03:05 PM Re: How does update work?
Average Talker

Posts: 27
Trades: 0
Thanks a lot for all of your help, I really appreciate it. There is just one last leg of the problem left
How do I execute it? Is there a certain command that if I run will update the table?
And how will it know that I want data table from s_data database? I have other tables named data in the other databases.
__________________
Those who can: learn. Those who can't: teach.
Cinatas is offline
Reply With Quote
View Public Profile
 
Old 01-07-2010, 03:13 PM Re: How does update work?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You need to read up on the basics of MySQL. Try the tutorials on tizag.com.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 01-07-2010, 03:21 PM Re: How does update work?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
How do I execute it?
The same way the code is executed earlier in your code
PHP Code:
$SQL "SELECT * FROM `data`";
$result mysql_query($SQL); 
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to How does update work?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28196 seconds with 12 queries