0

I want to submit a text area where user can enter anything or any special characters with the same text format as user input into the text area. Like spaces, new line and tab at the start of the new line. I have one the below codes but when the user input contain ',",(,) it showing the sqlquery error. Please let me know how to insert text like forum into the database.

html is

<textarea class="noticearea" name="notice_area" id="notice_area" ></textarea>

php is

$noticeinsert = mysql_query("INSERT INTO notice_board(notice_id, notice_area, notice_dnt) VALUES ('$notice_id', '$notice_area', '$notice_dnt')"); 

please let me know how to submit any enter value into the database. Also, is it safe to send html or php codes or speicial char entered by users into database ?

user2642907
  • 121
  • 1
  • 1
  • 11
  • this kind of embedding string from variables that are filled with user input content makes you potentially vulnerable to sql injections. – DrCopyPaste Sep 13 '13 at 10:07
  • You need to sanitize and escape your inputs. Look into prepared statements. – Ben Fortune Sep 13 '13 at 10:07
  • can u please explain me clearly – user2642907 Sep 13 '13 at 10:09
  • 2
    In this case `mysql_real_escape_string()`, `stripslashes()` etc, but you should look into mysqli/PDO. – Ben Fortune Sep 13 '13 at 10:10
  • #ben fortune, i saw the above comment that embedding string from varaible are vulnerable if i use mysql_real_escape_string it is also the same problem ?? – user2642907 Sep 13 '13 at 10:17
  • yes vulnerability remains, take a look here http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string to get around this use parametrized/prepared statements – DrCopyPaste Sep 13 '13 at 11:39

3 Answers3

0

Change :

 <textarea class="noticearea" name="notice_area" id="notice_area" </textarea>

To:

  <textarea class="noticearea" name="notice_area" id="notice_area"></textarea>
trrrrrrm
  • 11,362
  • 25
  • 85
  • 130
0

You forgot $_POST.

Change

$noticeinsert = mysql_query("INSERT INTO notice_board(notice_id, notice_area, notice_dnt) VALUES ('$notice_id', '$notice_area', '$notice_dnt')"); 

To

$noticeinsert = mysql_query("INSERT INTO notice_board(notice_id, notice_area, notice_dnt) VALUES ('$_POST["notice_id"]', '$_POST["notice_area"]', '$_POST["notice_dnt"]')"); 

But check the $_POST variables, because of sql-injection.

q0re
  • 1,401
  • 19
  • 32
0

you are missing > in your html file

Guru
  • 621
  • 1
  • 4
  • 12