jponte Posted February 17, 2010 Share Posted February 17, 2010 Hi, I'm new to PHP and MySQL but so far so good trying to get done what I need to do. I seem to get stuck displaying an array value inside a form text box. This is what I have but it does not work // Connects to your Database mysql_connect("localhost", "root", "escrma") or die(mysql_error()); mysql_select_db("rma_portal") or die(mysql_error()); // Collects data from "users" table $data = mysql_query("SELECT * FROM cust_info WHERE Cust_id = 'TDBANK1'") or die(mysql_error()); // puts the "users" info into the $info array $info = mysql_fetch_array( $data ); <input name="custID" type="text" size="45" VALUE="<? echo $info['Cust_ID']; ?>" My echos and prints work fine. But I would like the data inside the text box to be modified if any. echo $info['Password']; print $info["Username"]; Any help will be appreciated Quote Link to comment Share on other sites More sharing options...
sader Posted February 17, 2010 Share Posted February 17, 2010 Try this $info['cust_id']; instead $info['Cust_ID']; and see if it works. Also if inside box as current value u get smthg like "<? echo $info['Cust_ID']; ?>" then u should use longer php tags <?php ... ?>. Anyways to use short tag <? is bad practise since it depends of server configuration and traveling from one hoster to another u may have big issues, so dont be lazy always add those three chars "php" Quote Link to comment Share on other sites More sharing options...
jponte Posted February 17, 2010 Author Share Posted February 17, 2010 Hi, Thanks for the fast reply. I actually do see the code in the box. Howver when I add the PHP tags: <td width="274"><?php <input name="ShipAttention" type="text" size="45" VALUE="<? echo $info['Cust_ID'] ?>"> ?> </td> I get the error: Parse error: syntax error, unexpected '<' in C:\Documents and Settings\jack.ponte\Desktop\Website\form1.php on line 258. Thanks for your help Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 17, 2010 Share Posted February 17, 2010 No the correct way is <td width="274"><input name="ShipAttention" type="text" size="45" VALUE="<?php echo $info['Cust_ID'] ?>"></td> NOTE: Tags such as <? ?> and <?= ?> may not always work as a setting called short_open_tag may be disabled. Always use the full PHP tags, eg <?php ?> Quote Link to comment Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 short_open_tags = On. also <? echo $var ?> and <?=$var?> not always works with form correctly. example: $var = "Sander van Doorn"; u can experience problem in INPUT will appear only 'Sander' in this case try using <?=nl2br($var)?>, works well. hope was helpful. Quote Link to comment Share on other sites More sharing options...
jponte Posted February 17, 2010 Author Share Posted February 17, 2010 Thanks everyone. The short tags were the problem although I had enabled them in my WAMPS server config. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 17, 2010 Share Posted February 17, 2010 short_open_tags = On. also <? echo $var ?> and <?=$var?> not always works with form correctly. example: $var = "Sander van Doorn"; u can experience problem in INPUT will appear only 'Sander' That is completely wrong. The reason why 'Sander' will only appear in the input box is probably because you're not wrapping your HTML attribute values in quotes. Wrong $somevar = "Sander van Doorn"; echo "<input type=text name=somename value=$somevar />"; The above will result in just 'Sande' being showing in the text box. It will treat 'van' and 'Doorn' as HTML attributes. All attribute values SHOULD be wrapped in quotes to prevent problems like this. The correct way is $somevar = "Sander van Doorn"; echo "<input type=\"text\" name=\"somename\" value=\"$somevar\" />"; //OR echo '<input type="text" name="somename" value="'.$somevar.'" />'; in this case try using <?=nl2br($var)?>, works well. I doubt it. Do you even know what nl2br is used for. Quote Link to comment Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 may be, i never wrap value="" ) nl2br used to break line by \n\r in this case nl2br() also works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.