Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:38:21+00:00 2026-05-17T17:38:21+00:00

I cannot get my addslashes function and html option value to play nice together.

  • 0

I cannot get my addslashes function and html option value to play nice together. My initial problem was the single quote in the option but by solving that I seem to have created another issue whereby $titleunit_name only comes through with the first word.

This is what I want to come out:

baroffice=O’Fallon & Highway K&N

titleunit_name=O’Fallon & Highway K&N

cleantitleunit_name=O\’Fallon & Highway K&N

This is what I get:

baroffice=O’Fallon

titleunit_name=O’Fallon & Highway K&N

cleantitleunit_name=O\’Fallon & Highway K&N

I don’t know if it matters but the values are normally coming from and being sent back to ms sql.

<form method="post" action="formtest.php?" id="searchform" target="" autocomplete="off">


<div id="office">

<font style="font-size:12px; font-weight:bold;" color="#002EB8" face="Verdana">
Closing Office:</font>

<select name="baroffice" style="width:90px">
<?php
$titleunit_name= "O'Fallon & Highway K&N";
$cleantitleunit_name=addslashes("$titleunit_name");

echo "<option value=$cleantitleunit_name name= '$titleunit_name'>"; 
echo "$titleunit_name</option>";

?>
</select></div><br>
<br><Br>
<input type="submit" name="submit" value="submit" style="position:relative;z-index:3">
<br><Br>
</form>

<?php
$baroffice = str_replace("\'","'",($_POST['baroffice']));

if (isset($_POST['submit']))
{

echo "baroffice=$baroffice<br>";
echo "titleunit_name=$titleunit_name<br>";
echo "cleantitleunit_name=$cleantitleunit_name<br>";


}
else
{echo "";
};

?>

Thanks for any help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:38:22+00:00Added an answer on May 17, 2026 at 5:38 pm

    First of all, you don’t need double quotes around variables. Just $titleunit_name is correct, not "$titleunit_name".

    Second, never use addslashes. If you’re escaping content to go into MySQL use the more robust mysql_real_escape_string function. addslashes misses cases and leaves your script every bit as open to attack as if you hadn’t used it at all.

    And finally, slashes do not belong in HTML output. You’re looking for the htmlspecialchars function, which prepares a string to be written into an HTML document.

    echo '<option value="' . htmlspecialchars($titleunit_name) . '" name="' . htmlspecialchars($titleunit_name) . '">' . htmlspecialchars($titleunit_name) . '</option>';
    

    Note that all uses of $titleunit_name (or any other variable) must be escaped in this way before writing them out to the page.

    Now, I’m guessing from context that you have “magic quotes” turned out, so PHP is automatically performing an addslashes on incoming POST data. If so, turn off magic quotes, and when it’s time to insert a string into the database perform the appropriate escaping then. If this is not possible, then use stripslashes to strip the slashes from all POSTed data at the beginning of the script execution so that you’re getting the data as submitted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get Raphaël working in a UIWebView. I load a simple HTML-Webpage with
I tried so hard but I just cannot get a simple Richfaces AjaxStatusTag inserted
I cannot get a two-way bind in WPF to work. I have a string
I cannot get the internet explorer web developer tool bar to work with a
I cannot get std::tr1::shared_ptr for my WinMobile project since the STL for WinCE is
For the life of me, I cannot get the SqlProfileProvider to work in an
For some reason, no matter how I go about it, I cannot get TortoiseSVN
I'm terribly new to SQL, and cannot seem to get the desired information out,
I get this message: Cannot find the X.509 certificate using the following search criteria:
I get this warning from GCC: warning: cannot pass objects of non-POD type 'class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.