codingcasually Posted November 22, 2014 Share Posted November 22, 2014 I'm writing a program that allows users to input a stock and view a historical price chart. Code is straight out of libchart charting library. Problem is, user is supposed to enter the stock symbol from a form handler (index.php) which then passes the symbol as a variable to the charting function, which doesn't get called at all: <? php function index() { chart($_POST['userinput']}; } ?> . <?php function chart($stock) { $prices=getdata($stock); //returns array of prices from yahoo finance $data=analyzer($prices); //produces metrics to be charted graph($data); } ?> //plots the metrics, outputs .html chart.php works on its own, as I've verified by hardcoding $argv='ibm'; in its code body. But index.php can't seem to call chart.php, as I've verified by including an echo/var_dump line in chart.php (doesn't get executed at all). It doesn't have anything to do with form handling either, as chart('ibm'); doesn't call chart.php either. I don't understand how a 6-line piece of code can be so problematic. All files are in the same folder, btw. Thanks. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 22, 2014 Share Posted November 22, 2014 your first php tag, isn't one. it's a <? followed by a space, then the php. if you look at the view source of your output in your browser, you will see the raw php code since it wasn't seen as being php code on the server and was sent to the browser as is. Quote Link to comment Share on other sites More sharing options...
codingcasually Posted November 22, 2014 Author Share Posted November 22, 2014 @mac_gyver: sorry, my bad, I didn't copy and paste that code, which I should have. It was so short that I decided to just type it right there. The original is tagged correctly, I would've noticed the syntax highlighting otherwise. It's still square 1 for me. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 22, 2014 Share Posted November 22, 2014 (edited) You are calling the chart() function within you index() function. When is that function being called? Also make sure you include chart.php before calling your chart() function. Also enable error reporting at the top of your script <?php ini_set('display_errors', 1); error_reporting(E_ALL); // rest of your code Edited November 22, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
codingcasually Posted November 23, 2014 Author Share Posted November 23, 2014 @chou3r: thanks for the suggestions, I did previously added include, and require as well, the latter just so it would trigger a fatal error if in fact something was wrong. Still got a blank page. Likewise when I incorporated your suggested error reporting. Thanks for the tip though. Puzzles me how such a spartan script can still fail. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 23, 2014 Share Posted November 23, 2014 <?php function index() { chart($_POST['userinput']); } ?> Quote Link to comment Share on other sites More sharing options...
codingcasually Posted November 23, 2014 Author Share Posted November 23, 2014 @quickoldcar: that is exactly how my non-functioning script looks like. I'm afraid that errant } in my code above was inadvertently carried over from my copying and pasting. Besides, that would have thrown off a syntax error.Thanks though. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 23, 2014 Share Posted November 23, 2014 You have not mentioned how index() being called? Quote Link to comment Share on other sites More sharing options...
Solution NotionCommotion Posted November 23, 2014 Solution Share Posted November 23, 2014 <?php ini_set('display_errors', 1); error_reporting(E_ALL); echo('sanity check1'); require_once('/path/to/chart.php'); chart($_POST['userinput']); echo('sanity check2'); ?> Quote Link to comment Share on other sites More sharing options...
codingcasually Posted November 24, 2014 Author Share Posted November 24, 2014 Finally, it's working! I had include 'chart.php', which wouldn't trigger an error warning. Thanks to @notioncommotion's suggestion, I used require instead, plus absolute, not relative path. Not sure why using absolute path would've made a difference, but it did. Thanks guys, this had been driving me crazy for a week. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 24, 2014 Share Posted November 24, 2014 Your welcome! It is easy to make a silly mistake with relative paths. require() or require_once() (which you want for your situation) at least make the mistake obvious. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.