Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
PHP Total of Var & Constant
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="JSEB" data-source="post: 472832" data-attributes="member: 92333"><p>I am fairly new to PHP, I am trying to get the total for a variable and a constant.</p><p>My variable is a random integer, and I need the total of $shirts bought, to match the price point I have set as my constant 'SHIRT_PRICE'</p><p>I hope I explained this well, the code I have currently:</p><p></p><p>[CODE=php]<?php</p><p> define ('SHIRT_PRICE', '17.99');</p><p> $shirts = rand(1, 10);</p><p> echo $shirts_total = ($shirts += 'SHIRT_PRICE');[/CODE]</p><p></p><p>The error I am getting: <strong>Fatal error</strong>: Uncaught TypeError: Unsupported operand types: int + string in C:\xampp\htdocs\clothing_sales.php:32 Stack trace: #0 {main} thrown in <strong>C:\xampp\htdocs\clothing_sales.php</strong> on line <strong>32</strong></p></blockquote><p></p>
[QUOTE="JSEB, post: 472832, member: 92333"] I am fairly new to PHP, I am trying to get the total for a variable and a constant. My variable is a random integer, and I need the total of $shirts bought, to match the price point I have set as my constant 'SHIRT_PRICE' I hope I explained this well, the code I have currently: [CODE=php]<?php define ('SHIRT_PRICE', '17.99'); $shirts = rand(1, 10); echo $shirts_total = ($shirts += 'SHIRT_PRICE');[/CODE] The error I am getting: [B]Fatal error[/B]: Uncaught TypeError: Unsupported operand types: int + string in C:\xampp\htdocs\clothing_sales.php:32 Stack trace: #0 {main} thrown in [B]C:\xampp\htdocs\clothing_sales.php[/B] on line [B]32[/B] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
PHP Total of Var & Constant
Top