Jump to content

Insert single quotes from text area


Call-911

Recommended Posts

Hello all.

 

I have a textarea on a form that users are posting new's stories into. Most are just copy/pasteing from Word, and they need to be able to include single quotes.

(ie: John's favorite store is Micky's)

 

I can't figure out how to make the single quotes (') into double quotes ('') so MSSQL will insert them in.

 

Any help? Here's my process code:

 

<?php
$title = $_POST['title'];
$district = $_POST['district'];
$central = $_POST['central'];
$east = $_POST['east'];
$north = $_POST['north'];
$west = $_POST['west'];
$story = $_POST['story'];
$date = date("l, M j, Y");
$sqlpicturename = "$picturename.jpg";
$showpicture = $_POST['showpicture'];




//declare the SQL statement that will query the database
$query = 
"
INSERT INTO News (district, central, east, north, west, date, title, story, picture, 

showpicture, show)

Values ('$district' , '$central', '$east' , '$north', '$west' , '$date', '$title' , 

'$story', '$sqlpicturename' , '$showpicture' , 'true')

";

//execute the SQL query and return records
$result = mssql_query($query);



//display the results 

echo "Thank You For Posting Your Story:<b> $title </b><br /><br /><a 

href='addstory.php'>Click Here To Add Another Story</a><br /><br /><a href='index.php'>Click 

Here To Go Back To The WebEdit Menu</a>";
echo "<br /><br />";

mssql_close();

?>

Link to comment
Share on other sites

Since single quotes are escaped with another single quote, not escaped with slashes, or changed to a double quote, you can use str_replace to handle it. You should make sure magic_quotes_gpc() is off, or at least test for it, and if it's on run the data through stripslashes(). This can be wrapped into a function, if you want.

 

$data = "That isn't Dave's beach ball, it's Joe's."; // Test string
if( get_magic_quotes_gpc() ) {
$esc_data = str_replace("'", "''", stripslashes($data));
} else {
$esc_data = str_replace("'", "''", $data);
}
echo "<br>Before: $data<br>After: $esc_data"; // Demo results.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.