I am using laravel 4.2 and I am having a very weird problem while saving the data using the model.
I have a text area where user inputs some text and then hit the save button. it is saving fine when the text does not have any quotes in it. But gives issues when the text have some quotes.
For example: If I try to save "Hi. I am Jacky's friend." This text saves fine but when I check in the database there I see this "Hi. I am Jacky\\\'s friend." I get extra back slashes saved in the database.
This is my code :
Suppose $textnotes is the variables in which I am getting the entire text.
$savenotes = new Details(); // Details is the model and the table name is 'Details'
$savenotes->Notes = $textnotes; // 'Notes' is the column
$savenotes->save();
if(!empty($savenotes->id))
// My other stuffs here
I am unable to fix this. Any help will be appreciated.
This could be a PHP setting called Magic Quotes interfering with strings when they contain certain characters, rather than a Laravel specific problem. You can turn this off in your php.ini file, by following instructions in the documentation.
Related
I am working with php and i am trying to get data from "Editor" ( like Tinymyc),But
right now i am getting special characters like "<strong> ,<p>" etc..i just want to get simple data
without any special characters,how can i do this ?I tried with following code
$data=$_POST['editor'];
Give this a try - if your code is correct this should work.
$data = strip_tags($_POST['editor']);
i have a problem with the new implementet JSON storage in MySQL.
I am using mysql-5.7.12, jquery-2.1.1 and bootstrap-editable-1.5.1
The code looks like this:
<dt>Memo</dt>
foreach(json_decode($row['memo'], true) as $user => $memo) {
// $row['memo'] is something like: {"user":"very-long-text-with-some\\n escaped lines..."}
echo "
<dd><a class='memo' id='telephone-memo' data-pid='".$row['id']."' data-text='".$memo."' employee='".$user."'>new</a></dd>";
}
The a class='memo' ... is the x-editable.
A look inside the database shows no error. I can store more than enough inside the JSON string.
The problem is if i store more than 194 chars in the x-editable textarea, the data-text attribute shows empty! If this accures the user will overwrite his data with the next edit, because he/she did'nt see the actual stored data. Is there a limitation i did'nt know from?
I am exceedingly grateful for your help.
The Problem is solved!
I'm using since many years a UCFIRST() function in MySQL.
This is a 8-bit function!!
Normally used for names ect.
Function for the JSON-column removed and it works.
I am building a web application using CodeIgniter framework. The issue is that while uploading a file that have a single quote ' in the file name (Eg : Rob's.wmv) I get an empty file array in the controller. CI do have code to update the file name when the name contains special characters, but since the array is not set correctly the uploading doesn't take place. I can't understand what's going on, I tried debugging, it appears the uploading works fine on my local machine, but not on the server, this makes it even more interesting.
UPDATE The file array var_dump returns an empty array, so there's no way I can even get the file name in the script. The file array is not set, I don't get any information about the file at all.
You have to use the addslashes() from php.
The addslashes() function returns a string with backslashes in front of predefined characters.
example:
$var = "Rob's.wmv";
//then
$var = addslashes($var);
The predefined characters are:
single quote (')
double quote (")
backslash (\)
NULL
Tip: This function can be used to prepare a string for storage in a database and database queries.
As you upgrade your question:
please read this two article carefully, this is just a configuration problem. After that i think you are able to do it.
codeigniter-file-upload
how-to-upload-file-in-codeigniter
I'm trying to create a simple blog type system for my site using PHP and MYSQL.
everything works fine. however, the issue that I am facing right now is that when I insert data into mysql database, it will have some extra characters.
the extra character that I am having the most difficulty with is this: \
Example:
when I insert an image link/tag into database: I get the following in my database:
<p><img alt=\"\" src=\"http://somedomain.com/images/9Image1.jpg\" /></p>
so I am trying to remove those extra characters before inserting the data into mysql using PHP.
for that, I tried using the following code:
$body = preg_replace("/\\\\\/", "", $body);
however, this code doesn't do anything. and in fact stops my entire code working and it stops my code from inserting any data into mysql.
Could someone please advise on this issue?
Thanks in advance.
Try to use stripslashes(string)
$body = stripslashes($body);
Let me know if it works.
I have a form where I can also write HTML tags. I must save this textarea preserving every single HTML tag. So here's the code:
foreach($_POST["comment"] AS $key => $value)
{
mysql_query("UPDATE comments SET title= '".$value["title"]."', comment = '".$value['comment']."' WHERE id = '".$value["id"]."'");
}
When I try to save this:
<b>Hello</b>
In MySQL I get this result:
<b>Hello</b>
I must keep every single HTML as it is. If I write <b> I must save exactly <b> in database. I tryed escaping, html etities, quotes, strip slashes (...) but this guy keep saving everything in the wrong way.
p.s. Before you ask yes, description field is TEXT tupe with UTF-8 encoding.
Have you tried using http://php.net/manual/en/function.htmlspecialchars-decode.php on the mentioned value? This should do exactly what you're asking.
try running:
$sStr = '<b>Hello</b>';
echo htmlspecialchars_decode($sStr);
And it will be encoded properly. Feeding that to the database stores the value correct.
Also, but this is more of a side-notice, you really shouldn't save post data without validating the input. I do assume this is just a quick example and not production code? However, just a suggestion.
You need to escape the entry. If you are using the mysql method, you need the mysql_escape_string function like:
$string = mysql_escape_string("<br>Hello</br>");