Select WHERE problem

Discussion in 'PHP' started by gilgalbiblewheel, Nov 2, 2007.

  1. #1
    Where am I going wrong in this?
    
    <?php 
    $Keyword = $_GET["keyword"];
    $sql = "Select * FROM address WHERE $Keyword LIKE 'john'";
    ?>
    
    Code (markup):

     
    gilgalbiblewheel, Nov 2, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i'm not sure exactly how to do it, but from using MS Access, shouldn't it be WHERE $Keyword = LIKE 'john' ?
     
    Lordy, Nov 2, 2007 IP
  3. iwyrobi

    iwyrobi Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
     
    $name="john";
    $sql = "Select * FROM address WHERE $Keyword LIKE '" . $name ."'"; 
    Code (markup):
     
    iwyrobi, Nov 2, 2007 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    $name = "john";
    $sql = "Select * FROM tblname WHERE $keyword LIKE '%". $name ."%'";
     
    bartolay13, Nov 3, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    I guess input filtering isn't trendy anymore. :p
     
    nico_swd, Nov 3, 2007 IP
  6. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    Where do I go wrong
    line 56 is:
    	$query = odbc_exec($odbc, $sql) or die (odbc_errormsg());
    PHP:
    below.

    <?php 
    	
    	require_once('odbc.php');
    
    // Let's see what user wants to search for today :)
        $Keyword = $_GET["keyword"]; //Trim(Request.QueryString("Keyword"))
        $Keywordb = $_GET["keywordb"]; //Trim(Request.QueryString("Keywordb"))
        $Keywordc = $_GET["keywordc"]; //Trim(Request.QueryString("Keywordc"))
        $Keywordd = $_GET["keywordd"]; //Trim(Request.QueryString("Keywordd"))
        $Keyworde = $_GET["keyworde"]; //Trim(Request.QueryString("Keyworde"))
        $Keywordf = $_GET["keywordf"]; //Request.QueryString("Keywordf")
        $Keywordg = $_GET["keywordg"]; //Trim(Request.QueryString("Keywordg"))
        $spoke = $_GET["spoke"]; //Request.Querystring("spoke")
        $number = $_GET["number"]; //Request.QueryString("number")
        $id = $_GET["id"]; //Request.QueryString("id")
        $Keywordh = $_GET["keywordh"]; //Trim(Request.QueryString("Keywordh"))
    
    
    echo $Keyword;
    	$sql = "Select * FROM book WHERE";
    		
    if ($Keyword != "")
    	{
    		echo '<b>'.$Keyword.'</b>';
    		$myarray = split($Keyword, '+');
    		echo '<b>'.$myarray.'</b>';
    		$whereclause=" text_data LIKE '%".$myarray[0]."%'";
    		
    		for ($i=1; $i<=ubound; $i++)
    			{
    			$whereclause = $whereclause." AND text_data LIKE '%".$myarray[$i]."%'";
    			}
      
    		$sql = $sql.$whereclause;		
    		
    	}
    	 
    	echo '<b>'.$sql.'</b>';
    	$query = odbc_exec($odbc, $sql) or die (odbc_errormsg());
    	while($row = odbc_fetch_array($query))
    		{
    			echo '<option value="'.$row['letter_id'].'"> Spoke '.$row['letter_id'].'</option>'."\n"; 
    		}
    	odbc_close($odbc);
    ?>
    PHP:
     
    gilgalbiblewheel, Nov 5, 2007 IP