title: Parsing/Converting XML stock data and uploading to mySQL database
body: <p>This may not be the best way to do it, so I am open to opinions, but I want to pull data from my brokerage through their API and load it into mySQL database. I have php code that I developed to connect and retrieve XML data. Any coding assistance or guidance is greatly appreciated!</p>
  
  <p>What I want it to do:
  1. Be able to capture XML data as a variable
  2. Parse and upload XML data to mySQL table with the same field names (database and table already created).</p>
  
  <p>Background:
  1. I am new to PHP, but know html pretty well and learn fast.</p>
  
  <ol start="2">
  <li>I run a php file that retrieves data from my brokerage. I want to be able to:
  (a) capture an XML field as a variable (so that I can create tables based on individual values) and (b) upload XML data into tables</li>
  </ol>
  
  <p>I have read a lot of the threads on the forum and I am struggling to get something to work for me that's close.</p>
  
  <p>sample (obviously it's a lot longer) xml data returned from php data request (tkdataex.php):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;response id="e4985128-a402-4334-9e25-b86d930e9703"&gt;&lt;elapsedtime&gt;0&lt;/elapsedtime&gt;
  &lt;quotes&gt;
    &lt;quote&gt;
      &lt;issue_desc&gt;CALL MAR-02 $1550.00&lt;/issue_desc&gt;
      &lt;last&gt;0.0&lt;/last&gt;
      &lt;volume&gt;0&lt;/volume&gt;
    &lt;/quote&gt;
    &lt;quote&gt;
      &lt;issue_desc&gt;CALL MAR-02 $1575.00&lt;/issue_desc&gt;
      &lt;last&gt;0.0&lt;/last&gt;
      &lt;volume&gt;0&lt;/volume&gt;
    &lt;/quote&gt;
    &lt;quote&gt;
      &lt;issue_desc&gt;CALL MAR-02 $1600.00&lt;/issue_desc&gt;
      &lt;last&gt;0.0&lt;/last&gt;
      &lt;volume&gt;0&lt;/volume&gt;
    &lt;/quote&gt;
  &lt;/quotes&gt;&lt;error&gt;Success&lt;/error&gt;&lt;/response&gt;
  </code></pre>
  
  <p>my code so far (filloptionstable.php) returns server error:</p>
  
  <pre><code>&lt;?php
  
  $url = "tkdataex.php";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_URL, $url);    //get url contents
  
  $data = curl_exec ($ch);    //execute curl request
  curl_close($ch);
  
  $xml = simplexml_load_string($data);
  
  require_once 'dbconnect.php';
  $database = 'SPX';
  $table = 'SPXchain';
  
  
  foreach ($xml -&gt; quote as $row){
      $strikeprice = $row -&gt; strikeprice;
      $last = $row -&gt; last;
      $strikeprice = $row -&gt; volume;
      INSERT INTO chain (strikeprice, last, volume) VALUES ($stripeprice,$last,$volume);
  }
  
  ?&gt;
  </code></pre>
  
  <p>I know that this works for ONE entry manually specifying values, but I cannot figure out how to grab the XML values to make this dynamic (filloptionstablebasic.php):</p>
  
  <pre><code>&lt;?php
  
  $url = "testfull.php";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_URL, $url);    //get url contents
  
  $data = curl_exec ($ch);    //execute curl request
  curl_close($ch);
  
  $xml = simplexml_load_string($data);
  
  require_once 'dbconnect.php';
  $database = 'SPX';
  $table = 'SPXchain';
  
  $xdate = 20160302;
  $strikeprice = 1900 ;
  $delta = 0.082;
  $interest = 100;
  $volume = 120;
  $put_call = '"call"';
  $bid = 4.56;
  $ask = 4.90;
  $last = 4.72;
  $daychange = -0.24;
  $pull_time = CURRENT_TIMESTAMP;
  
  $sql = 'INSERT INTO SPXchain '.
        '(
          xdate,
          strikeprice, 
          delta,
          interest,
          volume,
          put_call,
          bid,
          ask,
          last,
          daychange,
          pull_time) '.
        'VALUES ( ' .
          $xdate . ', ' .
          $strikeprice . ', ' . 
          $delta . ', ' . 
          $interest . ', ' . 
          $volume . ', ' . 
          $put_call . ', ' .
          $bid . ', ' . 
          $ask . ', ' . 
          $last . ', ' .
          $daychange . ', ' . 
          $pull_time . ')';
  
  mysql_select_db('SPX');
     $retval = mysql_query( $sql, $conn );
  
     if(! $retval ) {
        die('Could not enter data: ' . mysql_error());
     }
  
  echo "Entered data successfully into " . $table;
  </code></pre>