Jump to content

Trouble parring single quote through post into table


pioneerx01

Recommended Posts

In one of my forms I am calling on all items stored in one table:

 

$query  = "SELECT item FROM item_table WHERE ";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{echo "<option value='{$row['item']}'>{$row['item']}</option>";}

 

So, basically I get a drop down menu with choices such as: Bob's Pen, Tom's Pencil, Mark's Paper,...

Users get to select one and submit that form which goes into table, but nothing after the quote gets stores so I get: Bob, Tom, Mark,... I know that ' and everything after that gets filtered out because when I directly echo the post I get what is submitted into the database (Bob, Tom, Mark, ...). Will I have to replace ' with something else as it gets submitted and then replace something else back to ' right before it gets stored into a table? Or is there a way I do not know of as to how to do it?

 

Thanks

Link to comment
Share on other sites

try changing...

{echo "<option value='{$row['item']}'>{$row['item']}</option>";}

to...

{echo "<option value='".$row['item']."'>".$row['item']."</option>";}

 

Why? They are essentially the same. There is nothing wrong (syntax wise) with the original code.

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.