Using PHP Variables as HTML Form Input Attributes -
is possible use php variables attributes in form inputs?
i have following variable declared:
$instock //number of items in stock
i use variable per below, code isn't working (the max constraint not being applied field):
print "<td><input type='number' name='product1' id='product1' min='0' max='<?php echo $instock ?>' value='0'></td>";
is legal, or attempting syntactically impossible? sorry if stupid question - i'm new @ this, , embarrass myself frequently. : /
it's possible, syntax incorrect though. you're double dipping on php brackets.
i prefer instead of using print, it's easier read, if ide doing syntax highlighting:
?><td><input type='number' name='product1' id='product1' min='0' max='<?php echo $instock ?>' value='0'></td><?php
you within print/echo statement, need have variable inline without brackets:
echo "<td><input type='number' name='product1' id='product1' min='0' max='$instock' value='0'></td>";
note without concatenation, works double quotes.
Comments
Post a Comment