Jump to content

Convert Form Text to HTML for database


mjurmann

Recommended Posts

Hello there! I am trying to convert text input by a user including line breaks and ' ' to html markup so that when it is inserted in the database, the ' and line breaks are converted into code so that when the information put in the database is echoed out, it does not stop echoing right before the ' and ignore the line breaks!

Help anyone?
Link to comment
https://forums.phpfreaks.com/topic/28068-convert-form-text-to-html-for-database/
Share on other sites

GetSQLValueString??

What it is this? sorry i didn't understand you.
but i can say you can use it directly in insert query too.
see this example.

$sql="insert into table_name (id,name) values ('$id','".addslashes($_POST['name']."')";

Let us know if you still had  a problem with it please post your piece of code here . :)

Joshi.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addlisting")) {
  $insertSQL = sprintf("INSERT INTO uploaded (type, name, URL, description, address, phone_number, email, imageURL) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['form_menu'], "text"),
                      GetSQLValueString($_POST['form_name'], "text"),
                      GetSQLValueString($_POST['form_url'], "text"),
                      GetSQLValueString($_POST['form_description'], "text"),
  GetSQLValueString($_POST['address'], "text"),
  GetSQLValueString($_POST['phone'], "text"),
  GetSQLValueString($_POST['email'], "text"),
                  GetSQLValueString($_POST['uploaded'], "text"));

I want DESCRIPTION to be the field that has the slashes applied to it. How do I write that?
I think you are using dreamweaver generated code for form insertion.anyway..


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addlisting")) {
  $insertSQL = sprintf("INSERT INTO uploaded (type, name, URL, description, address, phone_number, email, imageURL) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['form_menu'], "text"),
                      GetSQLValueString($_POST['form_name'], "text"),
                      GetSQLValueString($_POST['form_url'], "text"),
                      GetSQLValueString($_POST['form_description'], "text"),
                  GetSQLValueString($_POST['address'], "text"),
                  GetSQLValueString($_POST['phone'], "text"),
                  GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['uploaded'], "text"));

Replace it with this

[code]
<?php
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addlisting")) {
  $insertSQL = sprintf("INSERT INTO uploaded (type, name, URL, description, address, phone_number, email, imageURL) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                      "GetSQLValueString($_POST['form_menu'], "text")",
                      GetSQLValueString($_POST['form_name'], "text"),
                      GetSQLValueString($_POST['form_url'], "text"),
                      ".addslashes(GetSQLValueString($_POST['form_description'], "text")).",
                  GetSQLValueString($_POST['address'], "text"),
                  GetSQLValueString($_POST['phone'], "text"),
                  GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['uploaded'], "text"));
?>
[/code]


Try it.
Oh Sorry!
[code]
<?php
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addlisting")) {
  $insertSQL = sprintf("INSERT INTO uploaded (type, name, URL, description, address, phone_number, email, imageURL) VALUES ('$_POST[form_menu]','$_POST[form_name]','$_POST[form_url]', '".addslashes($_POST[form_description])."',          '$_POST[address]','$_POST[phone]','$_POST[email]','$_POST[uploaded]'));
?>
[/code]

Try this now!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.