Inputting variables containing apostrophes

Apologies if I have entered this incorrectly. I am a newcomer.

I have been presented with a database of Fuchsia Information

[COLOR=“Blue”]http://www.americanfuchsiasociety.org/linktoregistrationdatabase.php[/COLOR]

Many of the cuiltivars include apostrophes and although I have no problems in inputting the data or retreiving a complete list or even a list of fuchsias with the same beginning letter. For example the code will retrieve ‘Barbara’s Gem’ as well as ‘Barbara’

Code for retrieving Fuchsias with same initial letter (This works)

[COLOR=“Red”]<form action=“letterfind.php” method=“post”>
Input Letter:
<input type=text name=“letter”><br>
<input type=submit value=“Submit!”>
</form>

$letter = $_POST[‘letter’];

   $letter = $letter.'%';
   $query = "SELECT * FROM RegList where Cultivar like '$letter' ";

$result = mysql_query($query);
?>[/COLOR]

However if I try to retrieve a single cultivar containing an apostrophe i.e. ‘Barbara’s Gem’ I receive the following error
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/afs/public_html/singlecultivar.php on line 14

offending line

$num=mysql_numrows($result);

By Cultivar

[COLOR=“Red”]<form action=“singlecultivar.php” method=“post”>

Input Cultivar:
<input type=text name=“letter”><br>
<input type=submit value=“Submit!”>
</form>

$letter = $_POST[‘letter’];
$letter = $letter;

   $query = "SELECT * FROM RegList where Cultivar REGEXP "$letter"/";
   $result = mysql_query($query);
  
   $num=mysql_numrows($result); [/COLOR]

Any advice please

thanks

Tony

The error message

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/afs/public_html/singlecultivar.php on line 14
means that the last query failed.

$letter = mysql_real_escape_string($letter); 

If users are expected to select just the first letter, consider replacing the text box with a drop-down list

Thanks for that. Too obvious for me to see - but a drop down list would be great
Thanks

Also make sure you change mysql_numrows() to mysql_num_rows(). This will throw up an error.

Thanks Klav