Forum Moderators: coopster

Message Too Old, No Replies

PHP code

help for ohp code

         

sasip_hyd

6:37 am on Sep 27, 2007 (gmt 0)

10+ Year Member



Iam learning PHP programming. Can somebody tell me what is wrong with the code below?
The echo command for text field is showing as '$dataarray[0]' in the text field and not the actual
value of the variable.But echo $dataarray[0] is outputting the value correctly. Why? How can I
get the value of the variable in the text field? I am using PHP 5 and IE6 in windows XP
professional with ISS

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<?php
$dataarray=file("C:\sasi.txt");
?>
</head>
<?php
echo '<body>';
echo '<form name="form1" method="post" action="">';
echo '<input name="textfield1" value= $dataarray[0] readonly="true" >';
echo $dataarray[0];
echo '</form>';
echo '</body>';
?>
</html>

Habtom

6:44 am on Sep 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi sasip_hyd, Welcome to WebmasterWorld.

echo '<input name="textfield1" value= $dataarray[0] readonly="true" >';

You may try the following:

echo "<input name=\"textfield1\" value= \"$dataarray[0]\" readonly=\"true\" >';

OR

echo '<input name="textfield1" value="'. $dataarray[0] .'" readonly="true" >';

Habtom

sasip_hyd

9:04 am on Sep 27, 2007 (gmt 0)

10+ Year Member



Hi Habtom
Thank you. It worked. Can you tell me why my code did not work?
Thank you once again.
Sasi

Habtom

9:12 am on Sep 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simple reason is: A string in single quotes can't be parsed in PHP.

coopster

10:41 am on Sep 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



... and the PHP manual page on Strings [php.net] will give you a more in depth understanding.