Right im very new to php and kinda learning as i go, here is my code.

What it is, is when i search a part number it has to be matching the case e.g if i search a6725 it doesnt work but if i search A6725 its returns the result.

please help!!!

$qresult = mysql_query("SELECT * FROM products WHERE part = \"$pt\"");
    $row = mysql_fetch_array($qresult);
		{
		do 
		{
			echo "<tr><td>".$row['part']."</td></tr>";
			echo "<tr><td>".$row['desc']."</td></tr>";
			echo "<tr><td>"; 
				if ($row['part'] <> $pt){
					echo $none;
					}
				elseif ($row['qt'] == $qty){
   					echo $limit;
					}		
				elseif ($row['qt'] >= $qty){
   					echo $in;
					}
				elseif ($row['qt'] <= $qty){
   					echo $out;
					}
		}
		while($row = mysql_fetch_array($qresult));
		}	
		
	echo "</table>";

Dani AI

Generated

The symptom is a case-sensitive match on the part column. 's suggestion to broaden matching and 's client-side uppercase fix both work, but they are partial solutions. A more robust approach is to make the comparison case-insensitive on the server and use parameterized queries to avoid SQL injection.

Check the column/ table collation first (for example with SHOW CREATE TABLE products;). If the part column uses a binary or case-sensitive collation, change it to a case-insensitive collation (for example a _ci collation) so normal equality comparisons ignore case. That fixes searches for any client input without relying on JavaScript. If you cannot change the schema, you can compare normalized values in the query, but be aware that wrapping the column in a function will usually prevent an index from being used — for high-volume lookups prefer changing the collation or maintaining a normalized, indexed column.

Use prepared statements rather than interpolating variables into SQL. Example (PDO) showing server-side normalization:

$stmt = $pdo->prepare("SELECT * FROM products WHERE LOWER(part) = LOWER(:pt)");
$stmt->execute([':pt' => $pt]);
$row = $stmt->fetch();

For production: avoid the old mysql_* extension, always validate and normalize input on the server, and do not rely solely on client-side JS to change case (clients can bypass it). See the PHP documentation on prepared statements and the MySQL docs on collations for details and best practices:

PHP PDO prepared statements
MySQL character sets and collations

Recommended Answers

All 2 Replies

$query="SELECT * FROM products WHERE part  LIKE \"%$pt%\""

This will match any string in the column `part` where the substring/string contained in $pt is found

solved it thanks anyway used this in the form code

onBlur="this.value=this.value.toUpperCase()"

to force it to search in uppercase

ta

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.