problem with mysqli r/n

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

problem with mysqli r/n

Post by mekha »

hi guys...when i insert some text in the database...
i get it like this:

r/n my texttttttt/r/n/

...
i tryedd to use:

$string = $mysqli->real_escape_string($string2);

and nothing happen :S...any help please ?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: problem with mysqli r/n

Post by Celauran »

I don't see anything in that string that needs escaping, so I don't see a problem.
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: problem with mysqli r/n

Post by mekha »

right..no need...but what with the r/n// ... i tryed to remove the escaping...i still get /r/n// ... and tryed to update...the same problem...no clean results :S....still with /r/n//
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: problem with mysqli r/n

Post by s.dot »

If you don't escape it and still get \r\n in your string then it's in your original string. That or you're manipulating it when pulling it from the database and printing it. Show us more of your code.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: problem with mysqli r/n

Post by mekha »

this is my code :

Code: Select all

$sqlm = getPageById();
					if ($resultm = $mysqli->prepare($sqlm)) 
					{
						$mypageid = 216;
						$resultm -> bind_param("i",$mypageid); 
						$resultm->execute();	
						$resultm->store_result();
						$rowsm = $resultm->num_rows;
					}
					if($rowsm > 0)
					{
						$rowm = fetch($resultm);
						$pagetitle = $mysqli->real_escape_string($rowm[0]["page_title"]);
						$pageContent = $rowm[0]["page_content"];
						$pageurlname = $mysqli->real_escape_string($rowm[0]["page_name_url"]);
						
					}
and this is the "echo":

Code: Select all

<?=$pageContent?>
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: problem with mysqli r/n

Post by mekha »

and this is my query:

Code: Select all

function getPageById()
	{
		$sqlStr = "select * from tbl_pages where page_id = ?";
		return $sqlStr;
	}
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: problem with mysqli r/n

Post by mekha »

and this is what i send in post:

Code: Select all

$mysqli->real_escape_string ($_POST["page_content"]);
mekha
Forum Contributor
Posts: 112
Joined: Sat Mar 31, 2012 6:50 am

Re: problem with mysqli r/n

Post by mekha »

ok thank u guys... i solved it :D....
this is the solution:
i removed real_escape_string from $_POST["somename"];
....
and sure from the row.....in the row no need....

now when using a prepared statement in the query(insert,update,delete,select)...you do not need to use the real_escape_string in mysqli...because the prepared statement "makes the job"..
thank you every one ;) :D :!:
Post Reply