473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Apostrophe woes

Hello,

I have in my drop-down menu company names that can have apostrophe's
imbedded i.e. Vic's Coffee Shop which shows fine in the menu. However, when
the user updates other fields on the form and presses the update buton it is
truncating the company name field and it only sees the data in front of the
' sign i.e. Vic. You'll notice that right after the foreach($_POST as
$field => $value) I am echoing the results of each field and the company
field is truncated after the ' sign. Magic Quotes is on if this has anything
to do with the problem.

Can someone please tell me why???

TIA

Vic
Here's the code to load the dropdown menu:
<?PHP
$table = "tblCompanies";
$Link = mysql_connect ($host, $user, $password);
$Query = "select concat(compID,'; ',compName)
as comp_name from $table";
$results = mysql_db_query($database, $Query, $Link);
?>
<tr><td align="right"><b>Delivery Company:</b></td>
<td><select name = "theCompany" >
<Option Value=" ">Select Delivery Company:</option>
<?PHP
for($u=0;$u<mysql_num_rows($results); $u++)
{
$company=mysql_result($results,$u,'comp_name');
echo "<option value='$company'";
if ($company == $searchCompany)
{
echo "selected";
}
echo ">$company\n";
?>
</option>
<?PHP
}
?>
</select>

when the form is updated and the page is reloaded thiscode is run :

case "Update":
foreach($_POST as $field => $value)
{
echo "value of $$field is $value ;";

if ($field == "theCompany")
{
$$field = strip_tags(trim($value));
$pos = strpos($$field, ";");
$len = strlen($$field);
$searchCompany = $$field;
$compID = substr($$field, 0, $pos); // returns the company id
}
Jul 17 '05 #1
2 2389
Vic Spainhower wrote:
I have in my drop-down menu company names that can have apostrophe's
imbedded i.e. Vic's Coffee Shop which shows fine in the menu.
However, when the user updates other fields on the form and presses
the update buton it is truncating the company name field and it only
sees the data in front of the ' sign i.e. Vic.


Well now...

echo "<option value='$company'>"

Produces the following in your code:

<option value='Vic's Coffee Shop'>

I believe you see the problem? Try this instead:

echo '<option value="'.htmlspecialchars($company).'"';
if ($company == $searchCompany)
{
echo "selected";
}
echo ">$company\n";

--
Markku Uttula

Jul 17 '05 #2
Markku,

This certainly works and now I had better go read about the htmlspecialchars
function.

I am very new to php and I really do appreciate your help in this. I'm
certain I'd never have found this on my own.

Vic
"Markku Uttula" <ma***********@disconova.com> wrote in message
news:M6*************@reader1.news.jippii.net...
Vic Spainhower wrote:
I have in my drop-down menu company names that can have apostrophe's
imbedded i.e. Vic's Coffee Shop which shows fine in the menu. However,
when the user updates other fields on the form and presses
the update buton it is truncating the company name field and it only
sees the data in front of the ' sign i.e. Vic.


Well now...

echo "<option value='$company'>"

Produces the following in your code:

<option value='Vic's Coffee Shop'>

I believe you see the problem? Try this instead:

echo '<option value="'.htmlspecialchars($company).'"';
if ($company == $searchCompany)
{
echo "selected";
}
echo ">$company\n";

--
Markku Uttula

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Meyer1228 | last post by:
You all helped me with function keys last week. Thanks so much; your advice was right on. My question now - does anyone have a function that I can use to test my sql statements for the...
2
by: Michael Sterling | last post by:
i'm using delphi 7 and have a query in which i'm trying to find names that have an apostrophe in them, i.e. "o'mally". my problem is that when i write my select statement i can't get the quotes...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
1
by: congngo | last post by:
Hi all Every time I export a table into an excel spreadsheet. It has a leading apostrophe on every cells. This drive me nut. I have to do a work around by export table into a txt file than...
1
by: spacehopper_man | last post by:
hi - I am having "apostrophe in sql" problems ;) I am executing a stored procedure on SQL Server - and passing in a string parameter. the string has a single apostrophe in it. the call...
1
by: Rose | last post by:
Hi all, I'm trying to create a clickable link, but the pesky apostrophe is preventing the link from getting displayed properly. I'm displaying the contents of a folder (with contains the...
2
by: Tom | last post by:
Hi, I have some kind of problems with an apostrophe character ('). I would like to select from DataTable DataRow containing value horses' (with an apostrophe on the end). But when I do it in an...
9
by: Thomas 'PointedEars' Lahn | last post by:
Jukka K. Korpela wrote: IBTD. For example, in English it is customary (and AIUI expected) to use the character that ’ represents should be used to delimit a quotation within direct speech...
4
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.