Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    queries with apostraphes

    how come you can't use apostraphes in search queries? i have a music artist in the database called Caedmon's Call and it stops at Caedmon and the rest of the query has errors... can this be fixed somehow?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Use addslashes? OR if it's going through the url maybe rawurlencode?

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    thanks. addslashes didnt work for me. ill try rawurlencode

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by boeing747fp
    thanks. addslashes didnt work for me. ill try rawurlencode
    I'm not sure what you are trying to do.

    Are you using the artists name inside the where clause of a select?
    like
    PHP Code:
    $name "Jacky O'connor"  ;
    sql="select var from table where var2='" $name"'";     //--> will error
    sql="select var from table where var2='" addslashes($name) . "'"   //--> will not error 
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    didnt work... the query works with addslashes but when i try to send the user a link with the name in it, it doesnt work. not even with rawurlencode

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what do you mean by 'doesn't work'
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    here's my code
    ---------------------
    PHP Code:
    <?php
                 $con 
    mysql_connect("localhost","user","password");
                      
    $dd mysql_select_db("database",$con);
                      
    $sql "SELECT * FROM `spotlight`";
                      
    $result mysql_query($sql) or die ("Query Problem ".mysql_error());
                      while(
    $row mysql_fetch_array($result)){
                      
    $artist addslashes($row[spotlight]);
                      
    $spotlight rawurlencode($row[spotlight]);

    $sql2 "SELECT * FROM `cds` WHERE `artist` = '$artist' ";
                          
    $result2 mysql_query($sql2) or die("Query Problem: ".mysql_error());
        while(
    $row mysql_fetch_array($result2)){
                          
    $asin $row[7];
                          
    $theLocation="http://www.amazon.com/exec/obidos/tg/detail/-/$asin/1057thex-20/";
    $baseURL=""
    preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i""$theLocation"$matches);
    $theDomain "http://" $matches[2];
    $page $matches[3];
    $fd fopen($theDomain.$page"r");
    $value "";
    while(!
    feof($fd)){
        
    $value .= fread($fd4096);    
    }
    fclose($fd);
    $startstrpos($value'<b class="price">');  
    $finishstrpos($value'</b>');  
    $length$finish-$start;
    $value=substr($value$start$length);
    $FinalOutput preg_replace("/(href=\"?)(\/[^\"\/]+)/""\\1" $theDomain "\\2"$value);    
                            echo 
    "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                            echo 
    "<tr>";
                            echo 
    "<td align='center' width='23%' rowspan='3'><a class='three3' href='info.php?artist=$spotlight&album=$row[0]'><img src='$row[2]' border=1 width='50' height='49'></a></td>";
                            echo 
    "<td width='77%'><a class='three3' href='info.php?artist=$spotlight&album=$row[0]'><span class='searchTitle'>$row[1] - $row[0]</span></a></td>";
                            echo 
    "</tr>";
                            echo 
    "<tr>"
                            echo 
    "<td>";                       
                      if(
    $row[7] == ""){
                            echo 
    "<span class='priceStyle'>No Buy Options Yet Available.</span><br><span class='priceStyle2'>$row[5]</span>";
                            }
                            else{
                            echo 
    "<span class='priceStyle2'>Price:</span><span class='priceStyle'> ".substr($FinalOutput,0,24)."</span>";
                            echo 
    "&nbsp;<a class='three3' href='buy.php?asin=$asin'><img src='buynow.gif' border=0></a>";
                            }
                            echo 
    "</td>";
                            echo 
    "</tr>";
                            echo 
    "<tr>";
                            echo 
    "<td height='27'><a class='three3' href='info.php?artist=$spotlight&album=$row[0]'><span class='searchTitle11'>View More Details on This Album</span></a></td>";
                            echo 
    "</tr>";
                              echo 
    "</table>";
                            echo 
    "<hr color='orange' width='95%'>";
                            }            
    }
    ?>
    ----------------
    This is the part that isnt working...
    <a class='three3' href='info.php?artist=$spotlight&album=$row[0]'><span class='searchTitle11'>View More Details on This Album</span></a></
    Last edited by boeing747fp; 04-25-2004 at 12:30 AM. Reason: shortening

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I guess you're doing links like
    PHP Code:
    <a href='page.php?whatever=Caedmon's Call'>Caedmon's Call</a
    If you are then you will need to use both htmlentities and urlencode
    PHP Code:
    <a href='page.php?whatever=" . htmlentities(urlencode($variable)) . "'>Caedmons Call</a
    <edit>
    Got posts crossed
    </edit>
    Last edited by Nightfire; 04-25-2004 at 12:33 AM. Reason: posts crossed

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No. You just need to output valid html and use double quotes for the attribute-values. like

    href="info.php?artist=$spotlight&album=$row[0]"

    instead of
    href='info.php?artist=$spotlight&album=$row[0]'

    when you echo them out, this means that
    echo "&nbsp;<a class='three3' href='buy.php?asin=$asin'><img src='buynow.gif' border=0></a>";

    should be

    echo '&nbsp;<a class="three3" href="buy.php?asin=' . $asin . '"><img src="buynow.gif" border=0></a>';
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    http://whmx.com/store/spotlight.php <-this is the page im working on... and the section with Albums by Caedmon's Call works as far as the query and the Buy button, but the info page that you click on the album titles, images.


  •  

    Posting Permissions

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