SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    http://www.americanfuchsiasociety.org/linktoregistrationdatabase.php

    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)

    <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);
    ?>



    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

    <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);


    Any advice please

    thanks

    Tony

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,014
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    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.

    PHP Code:
    $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
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that. Too obvious for me to see - but a drop down list would be great
    Thanks

  4. #4
    SitePoint Zealot Klav's Avatar
    Join Date
    Mar 2002
    Location
    Huddersfield, UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also make sure you change mysql_numrows() to mysql_num_rows(). This will throw up an error.

  5. #5
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Klav


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •