Mato Mato - 2 months ago 7
SQL Question

Change my where query depend on input text

I want my input text to go in my where query, I can make it work with numbers, but when i try to search with letters in the input field. It doesn't work. Any suggestion? Do i need to convert something ?

<form name="form" method="get">
<input type="text" name="test">
<input type="submit" name="button1" value="Search">
</form>

$nickval = $_GET["test"];


This one is working.

//Establish connection to database
$host = "****";
$conn = ******
$query = " Select *
from p900
where p900key = $nickval
ORDER BY P900KEY";


This one doesnt work, In input i write AB which is signature.

//Establish connection to database
$host = "****";
$conn = ******
$query = " Select *
from p900
where p900SIG= $nickval
ORDER BY P900key";


Sorry if im unclear, i tried my best

Answer

For letters in where condition you have to wrapped textbox value in quotes like below.

//Establish connection to database
$host = "****";
$conn = ******
$query = " Select * 
from p900
where p900SIG= '$nickval'
ORDER BY P900key";