Jump to content

Code is not working


ksklos

Recommended Posts

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*/
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by benanamen
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.