I have the a textarea with the following value:
I save this value with php into my mysql database.
The result looks like this via phpmyadmin:
Now, I send a query with php to get the result and to show this text like this, to show it with line breaks:
<? echo nl2br($row->text); ?>
But the result will shown many withspaces. here the source code:
Where is my fault? :/
The result looks like this via phpmyadmin
phpadmin ist a webpage with html, it doesn't show consecutive blanks.
Where is my fault? :/
Somewhere between reading it out of the textarea, writing it into the database and reading it back from there.
Steps to track your problem.
What is transferred from the textarea to the server?
Check how the value is in your database.
Output the length of this string to get a simple idea of what really is in the database.
Then if you know if the string already got wrong into the database or the error occurs only when reading it, you can go on looking at this particular place.
Related
This is what is stored in my MySQL database:
But when I query it and display it in the browser, it is shown like this:
Just one line and not multiple like the original value in MySQL. How can I make my code so it keeps the same format as in the database? Thanks!
The browser will ignore or neglect the enter key that you stored in the database. However, browser will recognize the <br> tag. Just add the <br> in your PHP code when you want to print it out. Alternatively, you can have a look at nl2br function. This is the documentation
I have a table with date/time, temperature and humidity data stored on a mysql database.
I have a ugly looking but working HTML one so I made a new CSS table using templates and wanted to use the looping in PHP (as in the HTML) to fetch data to the table using the table designers format. (Some datas are manually in as in the sample table photo)
I want to automate that but my PHP script has a problem and does not load the page. shows error.
Im very new to LAMP environment actually and unsure if I can use class variables inside the PHP script without changing anything.
My table looks like this without the python script: https://imgur.com/a/WmpHzMZ
The code is here: https://codeshare.io/amvPYw
(I cannot add code here, it says bad formatting everytime)
Html element tags are close like </tr>. See your end line in while loop.
Note: I am using Laravel 5.1. I cannot tell at the moment whether this is related to Laravel or not, it works fine on my local machine with the exact same code as is on the server. So may be server related. I've given as much information as I can think of.
I have a textarea that a user can fill in, much like the textarea on this forum. When I try to repopulate that textarea from the database for editing, multiple new lines are lost.
The database shows this:
[b]some text[/b]\r\n
A: More text\r\n
\r\n
[b]other text[/b]\r\n
A: More other text\r\n
When I put it back in a textarea input it still has new lines, but double new lines are lost:
[b]some text[/b]
A: More text
[b]other text[/b]
A: More other text
I have tried this without using the blade escape syntax (just a plain echo) with the same result.
Infact I can't tell when it is losing the whitepace at all. Here are some examples of when I can see the string having multiple whitespace and when I can't.
dd($model);
// This shows with whitespace (/r/n) in both the attributes and originals array
dd($model->column);
// This shows the multiple new lines \r\n
var_dump($model->column);
// This shows no new lines
return $model->column;
// simple return from the controller removes multiple white lines
return Response::make($model->column);
// again just outputting the plain string multiple white lines are removed
<textarea>{!! $model->column !!}</textarea>
// of course the actual problem in a blade file, no extra spaces between lines are displayed in the textarea
What's more confusing is that in vagrant the whitelines are retained just fine, only on my centos server are they lost. The code is identical which made me think it might be a mysql/php/server setting, but then dd() on the model shows the correct whitespace so it's obviously coming out of the database just fine, something is happening to the string when it's echo'd or var_dump'd (i'm not sure what dd() uses I assumed it was var_dump, perhaps not).
It does seem to be related to the database in some way though, because a form with a validation error repopulates the textarea just fine with the multiple new lines. It's only when repopulating the textarea from the database that a problem occurs.
Every result i've found trying to google this error references using nl2br, which obviously isn't helpful in this instance. I'm not trying to display the text in html, i'm trying to let a user submit a form using the textarea and then refill that textarea to let them edit the data they've submitted later on. So to be very clear, nl2br is not a solution in this instance.
A year later and this was causing a problem again, finally figured it out, it was Cloudflare's minify html setting that was causing it.
I'm trying to realize a dynamic website for exercise. All contents are stored in the database:
I included html code(FORMS) as DB content with no ploblem, but when i try to insert php code as DB content nothing happens. The field type for Content is TEXT.
I tryed various ways :
INSERT INTO TableContent(Name_Content, Content, ID_Menu) values ("Amministration Area", "<?php include('LogIn.php')", 5);
INSERT INTO TableContent(Name_Content, Content, ID_Menu) values ("Amministration Area", "<?php include(\"LogIn.php\")", 5);
In the website page i see Amministrazion Area, but not what Login.php does.
I thought i made a mistake in Login.php page code so i changed it in a simply echo ("Hi"); but nothing appears anyway. I see only the text Amministration Area.
How can i solve it ?
It's just text! Text in a database. Nothing happens when you just insert text into a database and read from it. You have to actually get something to execute that text as PHP code. That doesn't happen automatically, thankfully! In PHP, the way to execute arbitrary strings as code is by using eval. But this is overall a very bad idea; storing all PHP code in a database is not making anything easier, on the contrary it makes everything more difficult to work with and more prone to exploits if you execute arbitrary code. I'd advice you to stop doing that and go back to PHP code in .php files, not databases.
PHP see <?php include("LogIn.php");? as a string, when you look in the source code of your file, you'll probably see it. It doesn't show up on screen because it starts with a <.
To execute the code instead of handling it as a string, you can use the eval() function.
You however don't want every row of your database be seen as PHP code, so you'll probably need to add a extra column that defines what the row is, i.e. a string, php code. Or you make an extra table where you store your includes.
I'm usually not the "scripting" guy
but I have been given a task, to create a script, that ping all our network equipments. (~300 devices) so I have come so fat, we can manage and edit the Excel and export as CVS into MySQL database, so far...
I have been searching around for a valid example to directly use the "IP" table from the database into my pingscript or to pull the SQL data and insert into a Array..
However, I have contact with the database, but I am unable to print the array data into my ping script however.
When I do a ECHO ['$databasename']; I get the result out, but I don't figure how to correctly input the table "IPaddr" into pingscript as a foreach from array...
I hope you can help me clearing this issue or correct me where I'm wrong :)
I can't post the code here, the site gives an error, so i posted on Pastebin:
PHP script can be seen here