Results 1 to 9 of 9

Thread: Help PHP!

  1. #1
    Join Date
    Nov 2006
    Posts
    1,939
    Tokens
    0

    Latest Awards:

    Default Help PHP!

    okies i keep gettin error message when am searching something.. here the link.. www.litelyrics.com/search.php and here the code..

    PHP Code:
    <?php
    require("db.php");
    if(isset(
    $_POST['search'])){
    $term =  $_POST['term'];
    $type $_POST['type'];
    if(!isset(
    $term)){ echo("Invalid search term specified!"); exit; }
    if(
    $type == "artist"){
    $query mysql_query("SELECT * FROM `lyrics` WHERE `artist` = '$term' ;");
    }elseif(
    $type == "song"){
    $query mysql_query("SELECT * FROM `lyrics` WHERE `song` = '$term' ;");
    }
    $rows mysql_fetch_array($query);
    if(!
    $rows[id]){ echo("Your search for <b>$term</b> returned no results in the LiteLyrics database."); exit; }
    echo(
    "You where searching for <b>$term</b> in <b>$type</b>'s:<br />");
    while(
    $rows mysql_fetch_array($query)){
    echo(
    "<a href=\"view.php?id=$rows[id]\">$rows[song] - $rows[artist]</a><br />");
    }
    }else{
    echo(
    "
    Please note that the LiteLyrics Search currently only supports exact matches.
    <br />
    <form method=\"POST\">
    Search: <input type=\"text\" name=\"term\" size=\"30\"> in <select name=\"type\"> <option value=\"artist\">Artists</option>
    <option value=\"song\">Tracks</option>
    </select> <input type=\"submit\" name=\"search\" value=\"Search\">
    </form>"
    );
    }
    ?>
    +REP for all helpers

  2. #2

    Default

    $query = mysql_query("SELECT * FROM `lyrics` WHERE `song` = '$term' ;");
    $query = mysql_query("SELECT * FROM `lyrics` WHERE `artist` = '$term' ;");

    remove the first ";" on each of those lines, so it looks like.

    $query = mysql_query("SELECT * FROM `lyrics` WHERE `song` = '$term' ");
    $query = mysql_query("SELECT * FROM `lyrics` WHERE `artist` = '$term' ");
    Managing Director
    Atomic Network Productions Ltd.
    The best in custom coding solutions.

  3. #3
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    remove the first ";" on each of those lines, so it looks like.
    Makes no difference. MySQL notices a ';' as a line breaker (end of query) so it wont prevent it from running.

    Run:
    PHP Code:
     <?php
    require("db.php");
    if(isset(
    $_POST['search'])){
    $term =  $_POST['term'];
    $type $_POST['type'];
    if(!isset(
    $term)){ echo("Invalid search term specified!"); exit; }
    if(
    $type == "artist"){
    $query mysql_query("SELECT * FROM `lyrics` WHERE `artist` = '$term' ;")or die mysql_error();
    }elseif(
    $type == "song"){
    $query mysql_query("SELECT * FROM `lyrics` WHERE `song` = '$term' ;") or die mysql_error();
    }
    $rows mysql_fetch_array($query);
    if(!
    $rows[id]){ echo("Your search for <b>$term</b> returned no results in the LiteLyrics database."); exit; }
    echo(
    "You where searching for <b>$term</b> in <b>$type</b>'s:<br />");
    while(
    $rows mysql_fetch_array($query)){
    echo(
    "<a href=\"view.php?id=$rows[id]\">$rows[song] - $rows[artist]</a><br />");
    }
    }else{
    echo(
    "
    Please note that the LiteLyrics Search currently only supports exact matches.
    <br />
    <form method=\"POST\">
    Search: <input type=\"text\" name=\"term\" size=\"30\"> in <select name=\"type\"> <option value=\"artist\">Artists</option>
    <option value=\"song\">Tracks</option>
    </select> <input type=\"submit\" name=\"search\" value=\"Search\">
    </form>"
    );
    }
    ?>
    Then tell me the error (if any). Oh and don't use this script for practical use until it's made secure.
    </span>
    Last edited by Invent; 20-11-2007 at 04:30 PM.

  4. #4

    Default

    Sorry I apologise, I have been doing Coldfusion for the last couple of months, and the query format is completely different.
    Managing Director
    Atomic Network Productions Ltd.
    The best in custom coding solutions.

  5. #5
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    2,016
    Tokens
    141
    Habbo
    florx

    Latest Awards:

    Default

    Also use LIKE so it doesn't only match exact

  6. #6
    Join Date
    Jun 2005
    Posts
    2,688
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
    include("db.php");
    $avaliable_terms = array('artist','song');

    if(isset(
    $_POST['search'])) {
        
    $term addslashes($_POST['term']);
        
    $type addslashes($_POST['type']);
        
        if(!
    in_array($type,$avaliable_terms)) $oh_no[] = "The search term doesn't match one of ours!";
        
        
    $query mysql_query("select * from lyrics where ".$type." like '%".$term."%' order by ".$type." asc");
        if(
    mysql_num_rows($query)==0$oh_no[] = "No results were found.";
        
        if(isset(
    $oh_no)) {
            
    $i=0;
            while(
    $i<count($oh_no)) {
                
    $oh_no_no .= $oh_no[$i]."<BR>";
                
    $i++;
            }
        }
        
        echo 
    "You searched for ".$term."<BR><BR>";
        if(isset(
    $oh_no_no)) {
            echo 
    $oh_no_no;
            die();
        }
        
        while(
    $row mysql_fetch_array($query)) {
            echo 
    "<a href='view.php?id=$row[id]'>$row[song] - $row[artist]</a><BR>";
        }
        
        die();
    }

    ?>
    <form method="POST">
    Search: <input type="text" name="term" size="30"> in <select name="type"> <option value="artist">Artists</option>
    <option value="song">Tracks</option>
    </select> <input type="submit" name="search" value="Search">
    </form>

  7. #7
    Join Date
    Sep 2004
    Location
    Liverpool
    Posts
    801
    Tokens
    0

    Default

    Quote Originally Posted by Baving View Post
    PHP Code:
    <?php
    include("db.php");
    $avaliable_terms = array('artist','song');

    if(isset(
    $_POST['search'])) {
        
    $term addslashes($_POST['term']);
        
    $type addslashes($_POST['type']);
        
        if(!
    in_array($type,$avaliable_terms)) $oh_no[] = "The search term doesn't match one of ours!";
        
        
    $query mysql_query("select * from lyrics where ".$type." like '%".$term."%' order by ".$type." asc");
        if(
    mysql_num_rows($query)==0$oh_no[] = "No results were found.";
        
        if(isset(
    $oh_no)) {
            
    $i=0;
            while(
    $i<count($oh_no)) {
                
    $oh_no_no .= $oh_no[$i]."<BR>";
                
    $i++;
            }
        }
        
        echo 
    "You searched for ".$term."<BR><BR>";
        if(isset(
    $oh_no_no)) {
            echo 
    $oh_no_no;
            die();
        }
        
        while(
    $row mysql_fetch_array($query)) {
            echo 
    "<a href='view.php?id=$row[id]'>$row[song] - $row[artist]</a><BR>";
        }
        
        die();
    }

    ?>
    <form method="POST">
    Search: <input type="text" name="term" size="30"> in <select name="type"> <option value="artist">Artists</option>
    <option value="song">Tracks</option>
    </select> <input type="submit" name="search" value="Search">
    </form>
    That's called neat efficient programming..anyone else heard of that round here?
    "A stupid man's report of what a clever man says can never be accurate, because he unconsciously translates what he hears into something he can understand."

  8. #8
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    Quote Originally Posted by Tomlegend View Post
    That's called neat efficient programming..anyone else heard of that round here?
    Except that the queries aren't in upper case, which is a personal pet peeve of mine Breaks it up from everything else in a script by having them upper case imo.

  9. #9
    Join Date
    Sep 2004
    Location
    Liverpool
    Posts
    801
    Tokens
    0

    Default

    Quote Originally Posted by benzoenator View Post
    Except that the queries aren't in upper case, which is a personal pet peeve of mine Breaks it up from everything else in a script by having them upper case imo.
    I rest my case.
    "A stupid man's report of what a clever man says can never be accurate, because he unconsciously translates what he hears into something he can understand."

Posting Permissions

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