ksklos Posted December 3, 2016 Share Posted December 3, 2016 Can someone look at this and tell me why it won't show on my website. I am kind of new to php. <?php /* file: index.php Author: Sue Klos Purpose: View Products */ $products[0] = array( 'name' => 'Sneakers', 'price' => $24.99, 'category' => 'Shoes', 'description' => 'Black', ); echo "<h2 styles='Text-align:center;'>Salter Tree and Herb Farm</h2> <h3>Our Products</h3> <p> " . $products[0]['name'] . "<br /> Price: $" . $products[0]['price'] . "<br /> Category: " $products[0]['category'] . "<br /> " $product[0]['Description'] . "<br /> </p>"; /*Note the ending quote of the quote on the echo line*/ ?> Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/ Share on other sites More sharing options...
Barand Posted December 3, 2016 Share Posted December 3, 2016 You have several syntax errors. Turn on error reporting and it will tell you where they are. Put this code at top of your code error_reporting(E_ALL); ini_set('display_errors', 1); Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540008 Share on other sites More sharing options...
ksklos Posted December 3, 2016 Author Share Posted December 3, 2016 I put the code at the top of my code but now I don't know what to do. I am using notepad++ to write my code. Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540010 Share on other sites More sharing options...
Barand Posted December 3, 2016 Share Posted December 3, 2016 Have you re-run the code to see what the errors are? Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540011 Share on other sites More sharing options...
mac_gyver Posted December 4, 2016 Share Posted December 4, 2016 putting the error settings in your file won't help with php syntax errors in the same file because the code never runs to cause the settings to take effect. you need to put these settings into the php.ini on your development system, which may require restarting your web server to get the changes to take effect. BTW - the currency symbol should not be stored with the price (hint as to where at least one error is at). it is a display property and should be handled when you display the price, not when you store the price. Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540016 Share on other sites More sharing options...
benanamen Posted December 4, 2016 Share Posted December 4, 2016 (edited) putting the error settings in your file won't help with php syntax errors in the same file because the code never runs to cause the settings to take effect. you need to put these settings into the php.ini Somebody correct me if I am wrong, but I believe turning on error reporting and setting display_errors at the top of a script is the exact same thing as setting it in the .ini except for it being a global setting. Edited December 4, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540017 Share on other sites More sharing options...
Jacques1 Posted December 4, 2016 Share Posted December 4, 2016 No. When the code is syntactically invalid, it doesn't get executed at all, so any runtime error settings have no effect. Besides that, it makes a lot more sense to set up a proper development environment with the right PHP settings rather than messing with the configuration on a per-script basis. Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540018 Share on other sites More sharing options...
benanamen Posted December 4, 2016 Share Posted December 4, 2016 No. When the code is syntactically invalid, it doesn't get executed at all, so any runtime error settings have no effect. Besides that, it makes a lot more sense to set up a proper development environment with the right PHP settings rather than messing with the configuration on a per-script basis. After testing, I see that is correct. I thought ini_set in the file overrode everything but it doesn't on syntax errors. Always a good day when I learn something new. Thank you gentlemen. Quote Link to comment https://forums.phpfreaks.com/topic/302677-code-is-not-working/#findComment-1540019 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.