Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6019083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:22:09+00:00 2026-05-23T03:22:09+00:00

The following piece of code gets a page via curl , extracts some strings

  • 0

The following piece of code gets a page via curl, extracts some strings from it and should update some MySQL columns.

My problem is that for the following code I’m an error (see under output below).

When I copy/paste the query and place it in the SQL editor in phpmyadmin, it works perfectly. Also, if I replace the parameters $price and $stockid in my code with the actual numbers that are listed in the output, it also works. How is that even possible?

If feel like I’m missing something really stupid.

$q = mysql_query("SELECT STOCK_TRADE_NAME,STOCK_ID FROM current_stocks WHERE STOCK_COUNTRY_ID = 7 LIMIT 1,9");
while ($row = mysql_fetch_array($q)) {
    $stockid = $row['STOCK_ID'];
    $url = "http://www.some.url.com/?stock_name=" . $row['STOCK_TRADE_NAME'];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    $dom = new simple_html_dom;
    $dom->load($output);
    foreach($dom->find('span.amount') as $e) {
        $price = str_replace(',','',$e->outertext);
    }
    foreach($dom->find('tr.even') as $f) {
        if (strstr($f->outertext,'<td class="name">Open</td>')) {
            $exp = explode('<td class="value">',$f->outertext);
            $open = str_replace('</td>','',$exp[1]);
        }
    }
    echo $stockid . " " . $price . "<br>";
    mysql_query("UPDATE current_stocks SET STOCK_CURRENT_PRICE = $price WHERE STOCK_ID = $stockid") or die(mysql_error());
    $ch="";  
    $dom="";

}

Output:

345 11.300
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '11.300 WHERE STOCK_ID = 345' at line 1

Note: STOCK_ID is INT(11), STOCK_CURRENT_PRICE is DECIMAL(8,3)

Note2: I’m using the latest MySQL/PhpMyAdmin/PHP version.

UPDATE:

Editing the query to this:

$q2 = "UPDATE current_stocks SET STOCK_CURRENT_PRICE = '" . $price . "' WHERE STOCK_ID = '" . $stockid . "'";
mysql_query($q2) or die(mysql_error());

Removes the error message, but does not update the db.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:22:10+00:00Added an answer on May 23, 2026 at 3:22 am

    If adding quotes doesn’t change anything, check for whitespace characters — maybe even inside $price. Is there a hidden tab or return that is not visible in html?

    Try something like $price = preg_replace("/'\s+'", '', $price); (not tested).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following piece of code should read each line of the file and operate
I have the following piece of code taken from the PHP manual on the
The following piece of code was given to us from our instructor so we
I'm a JavaScript beginner and managed to piece together to following code. It gets
The following piece of code is from u-boot: /* Initialize GOT pointer. ** Global
The following piece of code is called from a JMenuItem's ActionListener. Simply it launches
I was studying the following piece of code from WatiN which handles launching and
I inherited a piece of code from a recently-retired colleague that gets the total
Consider following piece of code: declare @var bit = 0 select * from tableA
The following piece of code shows an Insert table dialog: Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.