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
help on php/mysql logic
Old 03-08-2009, 05:02 AM help on php/mysql logic
Junior Talker

Posts: 4
Name: Frederick Wright
Location: Bulgaria
Trades: 0
here is a small page from which to enter data into my database and I can't get it to work.
Can anyone help to solve it.
Best
F

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<?php
require("./resources/globals.php");
//This is a PHP (4/5) script example on how eurofxref-daily.xml can be parsed
//Read eurofxref-daily.xml file in memory
$XMLContent= file("http://www.ecb.europa.eu/stats/eurof...xref-daily.xml");
//the file is updated daily between 14:15 and 15:00 CET
foreach ($XMLContent as $line) {
if (ereg("currency='([[:alpha:]]+)'",$line,$currencyCode)) {
if (ereg("rate='([[:graph:]]+)'",$line,$rate)) {
//Output the value of 1 EUR for a currency code

//echo '1 &euro; = '.$rate[1].' '.$currencyCode[1].'<br />';


$rate= ''.$rate[1].'<br />';
$currencyCode=''.$currencyCode[1].'<br />';

$updateStmt = "Update currency SET rate=$rate WHERE code = $currencyCode ";

// Connect to the Database
if (!($link=mysql_pconnect($location,$userName,$passw ord))) {
DisplayErrMsg(sprintf("error connecting to host %s, by user %s",
$location, $userName)) ;
//exit() ;
}
// Select the Database
if (!mysql_select_db($dbname, $link)) {
DisplayErrMsg(sprintf("Error in selecting %s database", $dbname)) ;
DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ;
//exit() ;
}
// Execute the Statement
if (!mysql_query ($updateStmt)){
// Execute the Statement
//if (!mysql_query($updateStmt, $link)) {
DisplayErrMsg(sprintf("Error in executing %s stmt", $updateStmt)) ;
DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ;
// exit() ;
}
///////////////////////////////////////////

}
}
}

?>
<body>
</body>
</html>
phobia1 is offline
Reply With Quote
View Public Profile Visit phobia1's homepage!
 
 
Register now for full access!
Old 03-08-2009, 05:18 AM Re: help on php/mysql logic
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
What error message are you getting if any? Also, it is much easier to read your code if it is properly formatted and if you use php tags ( [ php] [ /php] without the spaces):

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<?php
require("./resources/globals.php"); 

//This is a PHP (4/5) script example on how eurofxref-daily.xml can be parsed 
//Read eurofxref-daily.xml file in memory 

$XMLContentfile("http://www.ecb.europa.eu/stats/eurof...xref-daily.xml");

//the file is updated daily between 14:15 and 15:00 CET

foreach ($XMLContent as $line
{
     if (
ereg("currency='([[:alpha:]]+)'",$line,$currencyCode)) 
     {
          if (
ereg("rate='([[:graph:]]+)'",$line,$rate)) 
          {
               
//Output the value of 1 EUR for a currency code 
               //echo '1 &euro; = '.$rate[1].' '.$currencyCode[1].'<br />';

               
$rate''.$rate[1].'<br />';
               
$currencyCode=''.$currencyCode[1].'<br />';

               
$updateStmt "Update currency SET rate=$rate WHERE code = $currencyCode ";

               
// Connect to the Database
               
if (!($link=mysql_pconnect($location,$userName,$password))) 
               {
                     
DisplayErrMsg(sprintf("error connecting to host %s, by user %s",
                                        
$location$userName)) ;
                     
//exit() ;
               
}
               
// Select the Database
               
if (!mysql_select_db($dbname$link)) 
               {
                     
DisplayErrMsg(sprintf("Error in selecting %s database"$dbname)) ;
                     
DisplayErrMsg(sprintf("error:%d %s"mysql_errno($link), mysql_error($link))) ;
                      
//exit() ;
                
}
                
// Execute the Statement
                
if (!mysql_query ($updateStmt))
                {
                      
// Execute the Statement
                      //if (!mysql_query($updateStmt, $link)) {

                      
DisplayErrMsg(sprintf("Error in executing %s stmt"$updateStmt)) ;
                      
DisplayErrMsg(sprintf("error:%d %s"mysql_errno($link), mysql_error($link))) ;
                      
// exit() ;
                
}
///////////////////////////////////////////

          
}
     }
}

?> 
<body>
</body>
</html>
__________________

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
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-08-2009, 05:27 AM Re: help on php/mysql logic
Junior Talker

Posts: 4
Name: Frederick Wright
Location: Bulgaria
Trades: 0
Hi
oops yes you are right for the php tags...in future I'll make it right..promise.
There are no errors as such. if cut out all the mysql code below $updateStmt = "Update currency SET rate=$rate WHERE code = $curre
and add echo $updateStmt;
it works, what I want to do is to post all the data to my database aND IT DOESN'T work :-)
best
F
phobia1 is offline
Reply With Quote
View Public Profile Visit phobia1's homepage!
 
Old 03-09-2009, 12:59 AM Re: help on php/mysql logic
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
it's because you didn't write the mysql query properly
You need to change this
PHP Code:
$updateStmt "Update currency SET rate=$rate WHERE code = $currencyCode "


to

PHP Code:
$updateStmt "Update currency SET rate='".$rate."' WHERE code = '".$currencyCode."'"
it is happening because one of the database field is a varchar and you can't use query without single quote when varchar is concerned!
__________________
I AM THE BEAUTIFUL NIGHTMARE

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
dark_lord is offline
Reply With Quote
View Public Profile Visit dark_lord's homepage!
 
Reply     « Reply to help on php/mysql logic
 

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