SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: mysql query

  1. #1
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mysql query

    PHP Code:
    <?php require_once("../shared/common.php");
          
    session_cache_limiter(null);
          
    $tab "";
      
    $nav "";
         require_once(
    "../shared/header.php");
          require_once(
    "../classes/Localize.php");

       
    $s $_GET['s'];
    $limit=10
    $trimmed["comp_name"] = trim($_POST["fname"]);
    $trimmed["contact1"] = trim($_POST["lname"]);
    $trimmed["contact2"] = trim($_POST["lname"]);
    $trimmed["contact3"] = trim($_POST["lname"]);
    $trimmed["tele1"] = trim($_POST["tele"]);
    $trimmed["tele2"] = trim($_POST["tele"]);
    $trimmed["mobile1"] = trim($_POST["mobile"]);
    $trimmed["mobile2"] = trim($_POST["mobile"]);
    $trimmed"city"] = trim($_POST["cit"]);
    $trimmed["state"] = trim($_POST["stat"]);
    $trimmed["country"] = trim($_POST["count"]);

    // check for an empty string and display a message.
    if ($trimmed["comp_name"]==""&&$trimmed["contact1"]==""&&$trimmed["tele1"]==""&&$trimmed["mobile1"]==""&&$trimmed"city"]==""&&$trimmed["state"]==""&&$trimmed["country"]==""
      {
    $resultmsg "<p>Give a search parameter! </p>" ;  
      }

      if( isset (
    $resultmsg)){
    echo 
    "<p>".$resultmsg."</p>";
    exit();
    }

    //separate key-phrases into keywords
    while(list($key,$val)=each($trimmed)){
        if(
    $val<>" " and strlen($val) > 0){
        
    $val=strtoupper($val);
        
    $sql .= "($key LIKE \"%$val%\") AND ";
        }
    }
        
    $sql=substr($sql,0,(strlen($sql)-4));//this will eat the last OR
        
    $sql .= ") ORDER BY userid";
    this is not performing the correct query and giving error as follows
    "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'comp_name LIKE "%2%") AND (tele1 LIKE "%2%") AND (tele2 LIKE "%2%") ) ORDER BY u' at line 1"

  2. #2
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks its solved


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
  •