Jump to content


Photo

Using a PHP var for value


  • Please log in to reply
7 replies to this topic

#1 activeware

activeware
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 02:53 PM

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

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 March 2006 - 03:18 PM

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

$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 ---");

this will echo it out and we will see if it's all on 1 line
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 activeware

activeware
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 03:23 PM

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

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 28 March 2006 - 03:25 PM

Do a view source and post the actual html outputed.

#5 activeware

activeware
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 03:43 PM

[!--quoteo(post=359310:date=Mar 28 2006, 04:25 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Mar 28 2006, 04:25 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Do a view source 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">

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 March 2006 - 04:05 PM

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:
$Var_lang = $data['NAME'];
to
$Var_lang = str_replace(array("\r", "\n"), '', $data['NAME']);
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.

#7 activeware

activeware
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 06:23 PM

[!--quoteo(post=359333:date=Mar 28 2006, 05:05 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 28 2006, 05:05 PM) View Post[/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:
$Var_lang = $data['NAME'];
to
$Var_lang = str_replace(array("\r", "\n"), '', $data['NAME']);
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.



#8 activeware

activeware
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 11:39 PM

[!--quoteo(post=359386:date=Mar 28 2006, 07:23 PM:name=activeware)--][div class=\'quotetop\']QUOTE(activeware @ Mar 28 2006, 07:23 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users