SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Location
    Grand Rapids, MI
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am having problems with getting an apostrophes to show. I don't know whether it is a mysql problem, or with php3.

    On page viewinfo1.php3, I have:

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    &lt;table border="0" width="700" cellspacing="0" cellpadding="0"&gt;

    &lt;form action="validate.php3" method="post"&gt;
    &lt;p&gt;&lt;select name="sel_game" size="6"&gt;
    &lt;?php
    mysql_connect (localhost, usernaname, password);
    mysql_select_db (mydb);
    $query = "SELECT * FROM gameinfo ORDER BY game";
    $gameinfo = mysql_query($query) or die("Select Failed!");
    while ($gamename = mysql_fetch_array($gameinfo)) {
    echo "&lt;option value='",$gamename['game'],"'&gt;";
    echo $gamename['game']," (",$gamename['platform'],")";
    echo "&lt;/option&gt;";
    } ?&gt;
    &lt;option&gt;---------------------------------------------------------&lt;/option&gt;
    &lt;/select&gt;&lt;/p&gt;
    &lt;p&gt;&lt;br&gt;
    &lt;input type="submit" value="Go"&gt; &lt;/p&gt;
    &lt;/form&gt;

    [/code]

    This dynamically produces a select box, 6 lines deep, showing all the games in the database (from the query). When you select a game, and hit submit, it transfers the game name to validate.php3 as $sel_game. Here, a game with the name of "Sarge's Heroes" will show up right, with the apostrophe in the right spot.

    My validate.php3 code:

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    &lt;?php
    mysql_connect (localhost, username, password) or die("Unable to Connect to MySQL Server");
    mysql_select_db (mydb) or die("Unable to select DB");
    $query="select id, publisher, description FROM gameinfo WHERE game='$sel_game'";
    $game_array=mysql_query($query) or die("Publisher Select Failed!");
    $game_info=mysql_fetch_array($game_array);
    $game_id=$game_info['id'];
    $game_publ=$game_info['publisher'];
    $game_desc=$game_info['description'];

    ?&gt;

    &lt;table border="1" width="700"&gt;
    &lt;tr&gt;
    &lt;td width="13%"&gt;*&lt;/td&gt;
    &lt;td width="72%"&gt;You selected Game : &lt;?php echo $sel_game ?&gt;&lt;/td&gt;
    &lt;td width="15%"&gt;*&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td width="13%"&gt;*&lt;/td&gt;
    &lt;td width="72%"&gt;The ID for this game is : &lt;?php echo $game_id ?&gt;&lt;/td&gt;

    &lt;td width="15%"&gt;*&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td width="13%"&gt;*&lt;/td&gt;
    &lt;td width="72%"&gt;The Publisher for this game is : &lt;?php echo $game_publ ?&gt;&lt;/td&gt;
    &lt;td width="15%"&gt;*&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td width="13%"&gt;*&lt;/td&gt;
    &lt;td width="72%"&gt;The Description for this game is :&lt;br&gt;&lt;br&gt; &lt;?php echo $game_desc ?&gt;&lt;/td&gt;
    &lt;td width="15%"&gt;*&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;

    [/code]

    This takes the passed variable $sel_game and looks it up in the database to get the publisher, id number, and description to display it. However, when I run across a game like "Sarge's Heroes", the processing stops after the apostrophe. The HTML is still shown, however, nothing past the apostrophe is shown from the database. This code works for any other game name, and even works with apostrophes in the description field.

    The game name and publisher fields are varchar's, and the description area is a blob.

    Again, Any help is greatly appreciated.

    Mike



    [This message has been edited by mmccue (edited March 07, 2000).]

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Location
    Grand Rapids, MI
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The lesson of the day:

    Sometimes posting the help request makes you look at things in a new light, and whammo!, 5 minutes later the problem is fixed. That has been my experience here. 5 Minutes after posting, though I've been working on this all night

    My solution, which works as far as I know (as far as I see):

    The problem wasn't with mysql or php, I think it was with the passing the $sel_game, which held the string that contained the apostrophe. Instead of passing that string, I changed the select list to pass the value of the 'id' number of the game, then queried for the rest of the information, including the game name, on the validate.php3 page by looking up the id. This works.

    Can't tell you how much this board has helped me in my ventures! A truly autonomous support system

    Mike

  3. #3
    RAGE
    SitePoint Community Guest
    darn .. just when I was going to tell you to escape the quotes with \" instead of "



    ------------------
    Vinay Sahni, Coder .. specializing in php/mysql
    webmaster@realmz.net

    http://www.realmz.net
    Your #1 source of Webmaster Resources


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
  •