Textbox doesn't show properly - php

I'm using PHP to retrieve the data from a database.
Every time I retrieve it from database it doesn't show the whole letters. It's being removed off after space???
I want like the first text box, show all the letters
both code doesn't work
<input type="text" class="textinput" value=' . $r['newsletter_title'] . '>
<input type="text" class="textinput" value=' . htmlspecialchars($r['newsletter_title']) . '>
I checked the database it's showing the whole letters "80% sale On Day"
Does anyone knows what causes this? Any solution please!!!

You need to quote the value (and use htmlspecialchars):
<input
type="text"
class="textinput"
name="newsletter_title"
id="newsletter_title"
value="' . htmlspecialchars($r['newsletter_title']) . '"
/>
Which generates:
<input
type="text"
class="textinput"
name="newsletter_title"
id="newsletter_title"
value="80% sale On Day"
/>
Otherwise you're generating invalid html/xml (which is why it isn't working)...

Type escaping the content with htmlspecialchars() - http://www.php.net/manual/en/function.htmlspecialchars.php

The value of the value-attribute is not enclosed in quotes. Enclose the value of the value attribute in quotes. Use your browser to look at the HTML that you generate. Don't just look at how your browser renders that HTML.

<input type="text" class="textinput" name="newsletter_title" id="newsletter_title" style="width:500px;" value="' . htmlspecialchars($r['newsletter_title']) . '">
Problem Solved. Thanks guys!

Related

Textbox focusing second word

I have a problem in text box always focusing second word instead of first word. If I set Maxlenth=1 means it doesn't allow me to type. After pressing backspace only I can type. Help me out from this.
Here is my Code:
<input type="text" name="exMark[]" id='exMark' value=" " style="width:30px; height:20px; text-transform:uppercase;" maxlength='1'>
remove space from attribut value=" ". Change it to value="" or dont write it at all.
<input type="text" name="exMark[]" id='exMark' value="" style="width:30px; height:20px; text-transform:uppercase;" maxlength='1'>
Remove that extra space in value=" "

Using php variable in HTML

I am using a php variable in html. $userProfile['institute'] is displaying correct value whenever $userProfile['institute'] is non-empty. When $userProfile['institute'] is empty , it display '/'. What may be the issue here ?
Institute: <input type="text" name="institute" value=<?php echo $userProfile['institute']?> /><br />
You are missing a set of quotes for your value attribute
value="<?php echo $userProfile['institute']?>"
You should add double quotes around it like this (like you have wrapped value of type and institute attributes )
Institute: <input type="text" name="institute" value=" <?php echo $userProfile['institute']?>" /><br />

How to store a php variable with spaces into a html variable?

I have a php array element that would like to submit as a POST value but it is only accepting the first word due to the spacings. Below is my source code :
<input type="number" class="form-control" placeholder="Please enter the amount to order" size="5" name='.$row["fname"].' />
When the page is printed it shows as :
<input type="number" class="form-control" placeholder="Please enter the amount to order" size="5" name=Mussel in Chill Sauce />
As you can see, only the word "Mussel" was stored into the name variable of the html form. How do i store the full text "Mussel in chilli sauce" which is derived from my $row["fname"]?
Appreciate your help thanks
You should wrap them in quotes properly:
echo '
<input
type="number"
class="form-control"
placeholder="Please enter the amount to order"
size="5"
name="'.$row["fname"].'" />
';
Sidenote: Thats not a good name value, are you sure thats the value you want? You should consider putting other name value instead as this would look like inside the $_POST variable when its submitted:
Array
(
[Mussel_in_Chill_Sauce] => 1 // going to access this thru $_POST['Mussel_in_Chill_Sauce'] ?
)
Try this code name="'.$row["fname"].'"
Put quotes around attribute values with spaces in them.
For that matter, put quotes around all attribute values. They are sometimes optional and never forbidden.
I think that way to do will help you :).
name="'.$row["fname"].'"
Change your code to this to have name inside double-quotes
<input type="number" class="form-control" placeholder="Please enter the amount to order" size="5" `name="'.$row[fname']." />`

Wrap php variable in quotes before echoing

I need to use a php variable to echo the id into an input field:
<input type="text" id={{ strtolower($val) . "Field" }}/>
But with the code above the output is
<input type="text" id=waterField/>
I want the output to wrapped in double quotes like:
<input type="text" id="waterField" />
I am using laravel but am totally willing to accomplish it without.
Is there a simple way to accomplish this? Thank you.
That is pure php, considering you have short tags enabled.
<input type="text" id="<? echo strtolower($val) ?>Field" />
use
echo '<input type="text" id="'.strtolower(htmlspecialchars($val)). 'Field"/>';
OR idle way to use html and php is
<input type="text" id="<?php echo strtolower(htmlspecialchars($val)); ?>Field"/>
If $val can have quotes in it, then need to clear them by using htmlspecialchars.
Why not just:
<input type="text" id="{{ strtolower($val) }}Field"/>
You can simply add the double quotes into your html text. Escape the double quotes like this \" so php won't parse them and you're fine.

PHP - Set value in HTML-Form

I'm a PHP-Newbie and want to create a simple Website to manage my CD Collection.
I connect to a MySQL-Database and create for each table a PHP-Array.
No i want to be able to edit my CDs within HTML-Forms and submit it back to the MySQL-Database.
For that i create a for-loop and put each array-varaible into an HTML-Form, so i can edit the text und via submit UPDATE my Database.
I know there is an answer for my question: stackoverflow Answer
But this solution didn't work for me.
One line:
echo "<input name="Titel" type="text" size="30" value="<?php echo $alben[$i]['Titel']; ?>">";
This line doesn't work, an i don't understand why.
Can someone please help?
EDIT:
If i just say:
echo $alben[$i]['Titel'];
This work. But with the HTML-Form i'm getting this error message:
syntax error, unexpected T_STRING, expecting ',' or ';'
Because you need escape the quotes and remove the 2nd echo
echo "<input name="Titel" type="text" size="30" value="<?php echo $alben[$i]['Titel']; ?>">";
into
echo "<input name=\"Titel\" type=\"text\" size=\"30\" value=\"" . $alben[$i]['Titel'] . "\">";
period is string concatination
"a" . "b" becomes "ab"
if you are in php tag use this:
<?php
...
echo '<input name="Titel" type="text" size="30" value="'. $alben[$i]['Titel']; .'">"';
..
?>
if you are in html, use this:
<input name="Titel" type="text" size="30" value="<?php echo $alben[$i]['Titel']; ?>">

Categories