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
Values won't write to db
Old 03-16-2005, 11:45 AM Values won't write to db
Average Talker

Posts: 16
Trades: 0
I have set up this code that finally works in all aspects in the way I expected it to work except for one thing, the last 'if' doesn't write the values to the database. I know it is validating and is running the sql_query yet nothing shows up in the db. What did I do wrong?????

the code:
PHP Code:
while(!feof($fh)) 
{
$line fgets($fh,1024);
list(
$fcode) = explode("/n"$line);
$b='2';
$a = (int)substr($line01);
   if (
substr($fcode04) === "HEAD")
   {
    
$sql "INSERT INTO parsed_files (header_id) VALUES ('$fcode')";
    
mysql_query($sql);
    }
   if (
$a>0)
   {
    
$check=substr($fcode011);
    
$table mysql_query("SELECT code_id,valid_cust_code,current_points_earned,total_points_earned FROM codes");
        while (
$row mysql_fetch_assoc($table))
        {
        
$dataBaseValue=stripslashes($row['valid_cust_code']);
        
$updateIdentifier=($row['code_id']);
        
$currentTotal=stripslashes($row['current_points_earned']);
        
$totalEarned=stripslashes($row['total_points_earned']);
            if (
$dataBaseValue === $check
            {
            
$b='3';
            
$currentTotal++;
            
$totalEarned++;
            
$sql 'UPDATE codes SET current_points_earned = '.$currentTotal.', total_points_earned = '.$totalEarned.' WHERE code_id = '.$updateIdentifier.' LIMIT 1'
            
mysql_query($sql);
            }
                    
        }
            if (
$b==='2')
            {
            echo 
'we made it '.$fcode.'<br />';
            
$Total='1';
            
$Earned='1';            
            
$sql "INSERT INTO 'codes' (`code_id`, `valid_cust_code`, `current_points_earned`, `total_points_earned`) VALUES ('', '$fcode', '$Total', '$Earned')";
            
mysql_query($sql);
            }
    }
}
fclose($fh);
//unlink($datFile);
mysql_close($dbconnect); 
Hallmarc is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-16-2005, 12:01 PM Now I feel like an idiot!!!
Average Talker

Posts: 16
Trades: 0


PHP Code:
$sql "INSERT INTO 'codes' (`code_id`, `valid_cust_code`, `current_points_earned`, `total_points_earned`) VALUES ('', '$fcode', '$Total', '$Earned')"
should read like this:

PHP Code:
$sql "INSERT INTO codes (code_id, valid_cust_code, current_points_earned, total_points_earned) VALUES ('', '$fcode', '$Total', '$Earned')"
That's what happens when you try to copy and paste code from phpMyAdmin I guess!!!
Hallmarc is offline
Reply With Quote
View Public Profile
 
Old 03-16-2005, 03:14 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Try adding an or die() to your sql:

PHP Code:
$resultmysql_query("SQL QUERY HERE") or die(mysql_error()); 
Then if there is an error in your SQL you will see it in your browser when you run the script.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-16-2005, 03:32 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
The only problem I see with the first query is the single quotes around 'codes', they should be backticks. Did you edit that part? phpMyAdmin wouldn't put that in.

Backticks are used to differentiate from your field or table names and mySQL keywords. For example, if you had a field called "from", you'd need backticks around it's name when you used it in your query or else mySQL would get confused.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Values won't write to db
 

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.20178 seconds with 12 queries