1

I am having a problem trying to understand a line of code. The code is below:

<input name="startDay" type="text" maxlength="2" size="2" value="<?=$startDay?>">

This code line was part of the code for creating a table and so far, I believe that it basically creates a text field that allows the user to input data and allow us to retrieve the input using the name startday with php code.

The variable $startDay is the variable that will receive the input of the value inputted by the user. However, I do not understand this part of the code and the way it is formatted:

value="<?=$startDay?>"

Can someone explain how it works?

ruthless
  • 1,090
  • 4
  • 16
  • 36

3 Answers3

1

Well value="<?=$startDay?>" this code will set the default value for the input which you have set.

and <?= ?> this syntax is short method for directly echoing variable,

<?=$startDay?> is equal to <?php echo $startDay; ?>

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
  • Can I be able to write which assigns a value to $startDay and prints it out on the text field? – ruthless Sep 11 '13 at 04:46
  • @user2548635 yes, but you do not need to add `$startDay` because you only need to add `5` so i prefer you should write `` – Dipesh Parmar Sep 11 '13 at 04:47
  • I understand what you're saying. It's just that I plan to set the value of $startDay to the current day so I can't set a concrete value for it. – ruthless Sep 11 '13 at 04:51
0

It simply tells that you assigning $startDay variable value into input text. It does not assign value of your input back to $startDay variable, just prints $startDay value in input element.

Rameez
  • 1,712
  • 2
  • 18
  • 39
0

ok the line you have is written in php. this outputs a text field where $startDay is written out in php by the server as a default value for that input field. so in other words, the server is filling out that form in php using a variable it already has.

the <? and ?> are opening and closing php tags. $startDay is the php variable

spicy
  • 1
  • 1