Jump to content

Recommended Posts

Hi

I have created a web form

and 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 Great


Code 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
Link to comment
https://forums.phpfreaks.com/topic/6016-using-a-php-var-for-value/
Share on other sites

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
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: Invite

Nathan
[!--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">
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.
[!--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 that

But its still sizeing the button bigger than it should be.

[!--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 that

But 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 help

Nathan
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.