how it looksI need to set an input value in a php script
<php
<input value="<?php echo $_SESSION['logged_user']->login; ?>">
?>
As you might understand my does not work
Your PHP syntax is very confused. While inside of a <?php ?> section you're trying to directly write HTML, and trying to open another <?php ?> section.
Either get rid of the enclosing section:
<input value="<?php echo $_SESSION['logged_user']->login; ?>">
Or keep the enclosing section and use PHP code to output:
<php
echo '<input value="' . $_SESSION['logged_user']->login . '">';
?>
Related
Is it possible to echo php value into form label? Currently I can only echo into textbox which is editable for the user but I want it to be unable to edit like label, any way I can do so?
Below is for textbox which is able to work
<input style="color:#000000" type="text" value="<?php echo $account['Username']; ?>" name="name" required/>
I tried to echo in label but nothing shown in my web
<label for="fullname"><?php echo $account['Fullname']; ?></label>
Use the echo statement. Like this:
<label><?php echo ("this is a label");?></label>
Of course it is possible.
You can use the echo function like you used it before.
Make sure:
you are using PHP file (*.php)
index in array is not empty
you are using < ? php tags
Try this:
// index.php
<?php
$text = "privet";
?>
<label for="fullname"><?php echo $text; ?></label>
// output is <label for="fullname">privet</label>
read this http://php.net/manual/en/function.echo.php
be careful and read also this http://php.net/manual/en/function.htmlspecialchars.php
BTW: if it still does not working... just use dump to get the variable info
<label><?php echo $var; ?></label> // does not working
// ok -> then dump the var!
<?php var_dump($var); ?> // hmm.. lets see (maybe null or string(0)?) :-)
I am a beginner.
I created a simple generator of pictures and I would like that when he was generate code in the text box and not as plain text.
Please help.
So it should look like: http://i.stack.imgur.com/cXT7X.jpg
I suppose you are doing something like
echo $code;
to show your code; if this is the case so you only have to do it like this :
echo '<input type="text" name="my_code" value="' . $code . '">';
or
echo '<textarea name="my_code">' . $code . '</textarea>';
That's it
Use basic HTML FORM elements with readonly attribute.
<textarea readonly><?php echo $code; ?></textarea>
Just keep in mind that PHP generates HTML that the browser parses...
<input type="text" name="url" value="<?php echo htmlspeciachars($url,ENT_QUOTES); ?>">
its important to use ENT_QUOTES or some other kind of data filter to avoid XSS.
I didn't understand what i am saying but if you want to set the text inside the text input than you should use value element in input tag. For example your code should look like this :-
<input type="text" value="<?php echo $yourvalue;?>" />
Hope this works for you.
I have this part of the code of a plugin, which continues and has much php before it, fluidly without the ?> till the end of all the code.
function fivu_thumbnail_meta_box_html() {
echo '<label for="featured_image_url">';
_e("URL of featured image", 'fivu_textdomain' );
echo '</label> ';
echo '<input type="text" id="featured_image_url" name="featured_image_url" value="" size="30" />';
}
What i need is to change the input value="" (5th line) to this:
value="<?php get_post_custom_values("Poster"); ?>"
But as i am inside of an echo, the php is not interpreted as php but as normal text.
¿What can i do to make the php inside of the echo not to be interpeted as normal text?
EDIT: Ok, i am using
echo '<input type="text" id="featured_image_url" name="featured_image_url" value="' . get_post_custom_values("Poster") . '" size="30" />';
But i forgot, lol, i need to echo the value. So how do i add: echo $values[0]; ?
I don't like HTML in echo.
So Try :-
function fivu_thumbnail_meta_box_html() {
?>
<label for="featured_image_url">
<?php
_e("URL of featured image", 'fivu_textdomain' );
?>
</label>
<input type="text" id="featured_image_url" name="featured_image_url" value="<?php echo get_post_custom_values("Poster"); ?>" size="30" />
<?php
}
You don't need <?php again as you're already inside a PHP control. You simply need to concatenate your string with the get_post_custom_values function's return value, like so:
echo '<input ... value="'.get_post_custom_values("Poster").'" ... />';
So we have string + function's return value + string, three components which together contribute to the output of the input field HTML.
Use the string concatenation operator, .:
echo '<input type="text" id="featured_image_url" name="featured_image_url" value="' . get_post_custom_values("Poster") . '" size="30" />';
I have this input form which goes like this:
<input type="checkbox" name="vehicle" value="Bike" />
I want to print it inside this variable:
$return .= '<div class="flink">'.$checkbox.'</div>';
or can i assign it to any other variable?
How can i do it? I tried putting :
$checkbox.= '<input type="checkbox" name="vehicle" value="Bike" />';
Just add:
$return = '<div class="flink">'.$checkbox.'</div>';
echo $return; // Somewhere on the page.
It looks like you're defining it fine, you just may not be echoing it out on the page.
If you're looking to print a variable to the webpage, you can use several different commands.
The echo command is useful when the variable is HTML.
The var_dump command is useful for debugging purposes, as it works on all kinds of variables.
print_r is also nice, because it formats the output in a way that's readable.
<?php
$q="select * from stores";
$res=mysql_query($q);
$StoreOPtion = '<option value="">--select--</option>';
while($rs=mysql_fetch_object($res))
{
$StoreOPtion .= '<option value="'.$rs->StoreId.'||StoreName:'.$rs->StoreName.'.. Street:'.$rs->StoreStreet.'..Phone:'.$rs->StorePhone.'..Email:'.$rs->StoreEmail.'..Area:'.$rs->StoreArea.'..Pin:'.$rs->StorePincode.'">'.$rs->StoreName.'</option>';
}
?>
<select name="StoreName" type="text" id="StoreName" onchange="getStoreAdd()"/>
<?php echo $StoreOPtion; ?>
</select>
Here i am using dropdown box. ypu sehe this example and use it
I have following code:
$boxId = 1;
$explainationBox='<input type="button" id="<?php echo $boxId; ?>" value="send" onmousedown="javascript:callthis(<?php echo $buttonId; ?>);" class="button" />';
echo $explainationBox;
I am trying to save these values as html button inside of php variable explainationBox. But its not saving actual value of $boxId. It is just saving it as $boxId. As boxId is inside a for loop and will keep on changing. How can i do this?
You do not nedd <?php tag when this tag is already opened
Try this
$boxId = 1;
$explainationBox='<input type="button" id="'.$boxId.'" value="send"
onmousedown="javascript:callthis('.$buttonId.');" class="button" />';
echo $explainationBox;
PHP tags in a string are not parsed (unless given to some functions such as eval()).
Use string concatenation.
Change this...
"<?php echo $boxId; ?>"
...to...
"' . $boxId . '"
You may find it useful to enter and exit the php environment within the loop so you don't have so save that string as a variable at all.
for($i=1; $i<10; $i++){?>
<input type="button" id="ID<?=$i?>" value="send"
onmousedown="javascript:callthis('<?=$i?>');" class="button" />
<?php } ?>
So what we are doing is leaving the php environment as we open the loop (?>) then we give some raw html that will be plopped into the page as shown, no variable needed. Then while we are outside the php environment we use the <?= $variable ?> syntax to drop a php variable into the html language. And finally we re-enter the php environment by reopenning the php tags (<?php).
Note: That last ?> would go wherever you wanted to re-exit php again.
This code is working:
$boxId = 1;
$explainationBox='';
echo $explainationBox;
except for: "javascript:callthis('.$buttonId.');" call. In order to make this whole code work here is a solution for those who are looking:
$boxId = 1;
$explainationBox='';
echo $explainationBox;