activeware Posted March 28, 2006 Share Posted March 28, 2006 Hi I have created a web formand am calling a var from MYSQL and placing it as the value (display name) for the submit button, but when i do it is enlarging the button (height) see example:Current Code works ok:<input class="H1_Blue_no_background" type="submit" name="Submit" value="Invite">Produces eg. [Invite] Works GreatCode that does not work:// Note// lang_conver($lang_id,332); is returning the value: Invite// lang_conver is a function we have used.$lang_id = "1"; //English// 2 = French// 3 = German$tmp = lang_conver($lang_id,332);<input class="H1_Blue_no_background" type="submit" name="Submit" value="<? echo $tmp;?>">Produces:[img src=\"http://www.airnetwifi.com/images/button.gif\" border=\"0\" alt=\"IPB Image\" /]Crude drawing I know, but hopefully it explains what i am trying to show.Nathan Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/ Share on other sites More sharing options...
shocker-z Posted March 28, 2006 Share Posted March 28, 2006 This should work but not sure why the only thing i can think of is that \n is used and therefore creating a new line within the button.. try to echo the value back[code]$lang_id = "1"; //English// 2 = French// 3 = German$tmp = lang_conver($lang_id,332);//replace any \n with <br> therefore causing the same effect of a new line as wont normal..$tmp=str_replace("\n",'<br>',$tmp);//echo it out using --- as a guide to check before the var is outputted to tell if it goes to the next line..echo("--- $tmp ---");[/code]this will echo it out and we will see if it's all on 1 line Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21604 Share on other sites More sharing options...
activeware Posted March 28, 2006 Author Share Posted March 28, 2006 Its coming back as--- Invite ---The function we are using is:<?php function lang_conver($langid,$atrid) { include("./connect.php"); $connection = mysql_connect($host,$userhost,$dbpassword) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql_lang = "SELECT * FROM language_conversion WHERE LID='$langid' AND ATID='$atrid'"; $result_lang = mysql_query($sql_lang) or die ("Could not execute: " . mysql_error()); $data = mysql_fetch_assoc($result_lang); $Var_lang = $data['NAME']; mysql_close($connection); return ($Var_lang); }?>And the data in the Database is: InviteNathan Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21608 Share on other sites More sharing options...
trq Posted March 28, 2006 Share Posted March 28, 2006 Do a [i]view source[/i] and post the actual html outputed. Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21610 Share on other sites More sharing options...
activeware Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359310:date=Mar 28 2006, 04:25 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Mar 28 2006, 04:25 PM) [snapback]359310[/snapback][/div][div class=\'quotemain\'][!--quotec--]Do a [i]view source[/i] and post the actual html outputed.[/quote]<input class="H1_Blue_no_background" name="invite_email" type="text" size="30"><input name="invite_from" type="hidden" value="29962896"> <input class="H1_Blue_no_background" type="submit" name="Submit" value="Invite"> Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21616 Share on other sites More sharing options...
wildteen88 Posted March 28, 2006 Share Posted March 28, 2006 I guess it is becuase your database values have \n's in them and so this could be why you are getting a bigger than usual button. SO chnage the following line in your lang_conver function:[code] $Var_lang = $data['NAME'];[/code]to[code] $Var_lang = str_replace(array("\r", "\n"), '', $data['NAME']);[/code]Any values that si returned from the database will now have any newline (\n) or carriage returns (\r) stripped out so this should stop what is happening with your button. Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21633 Share on other sites More sharing options...
activeware Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359333:date=Mar 28 2006, 05:05 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 28 2006, 05:05 PM) [snapback]359333[/snapback][/div][div class=\'quotemain\'][!--quotec--]I guess it is becuase your database values have \n's in them and so this could be why you are getting a bigger than usual button. SO chnage the following line in your lang_conver function:[code] $Var_lang = $data['NAME'];[/code]to[code] $Var_lang = str_replace(array("\r", "\n"), '', $data['NAME']);[/code]Any values that si returned from the database will now have any newline (\n) or carriage returns (\r) stripped out so this should stop what is happening with your button.[/quote]Hi tried thatBut its still sizeing the button bigger than it should be. Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21683 Share on other sites More sharing options...
activeware Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359386:date=Mar 28 2006, 07:23 PM:name=activeware)--][div class=\'quotetop\']QUOTE(activeware @ Mar 28 2006, 07:23 PM) [snapback]359386[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi tried thatBut its still sizeing the button bigger than it should be.[/quote]Found the solution:<input class="H1_Blue_no_background" type="submit" value=<?echo lang_conver($lang_id,332);?>>You do not need the " (quotes) as Browser interprets it in the background as a string.Thanks for the helpNathan Quote Link to comment https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/#findComment-21764 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.