ubuntu_user
ubuntu_user

Reputation: 57

How to insert \n character in MySQL table from PHP form

I am trying a few hours now to add the character \n in a MySQL table. I have a form. If someone presses OK with no data given i want to pass in the table tha character \n.

I have tried this.

$null_value = '\n';
$null_value = mysql_real_escape_string($null_value);
mysql_query("INSERT INTO table (x,x) VALUES ('$null_value','$null_value');

But nothing happened. I would appreciate it if someone can help me out with this ?

Upvotes: 1

Views: 2842

Answers (3)

ubuntu_user
ubuntu_user

Reputation: 57

I would to thank everyone for your answers. The problem has been solved. I had an error in my IF Statement. I followed the answer with the addslashes().

Thanks again !

Upvotes: 0

Dolly Aswin
Dolly Aswin

Reputation: 2794

If you want to insert \n as new line, use double quotes " not single quote '

$null_value = "\n";

Upvotes: 5

RAUSHAN KUMAR
RAUSHAN KUMAR

Reputation: 6006

Simply put a new line in your string, don't use \n escape sequence as

INSERT INTO `person`(`id`, `name`) VALUES (11,"
                                       ")

In your case

$null_value = '
';
$null_value = mysql_real_escape_string($null_value);
mysql_query("INSERT INTO table (x,x) VALUES ('$null_value','$null_value');

Upvotes: 0

Related Questions