Solved: Problem was using htmlentities() when getting the value from my form which changes '>' and '<'
< becomes <
> becomes >which is not recognized by sql and thus causing my problem!
I wrote a basic website in HTML and PHP on c9.io that can send queries to an SQL DATABASE. Most queries I send work fine so long as they do not use greater than or less than operators which result in a syntax error. For example:
SELECT bTitle FROM Book WHERE bQuantity > 9;
Results in the error:
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 '9' at line 1
But if I simply use the equal operator it works fine.
SELECT bTitle FROM Book WHERE bQuantity = 10;
Not sure what I'm doing wrong or overlooking but would appreciate any input.
-edit- The code excerpt which creates the Book table which I am querying.
CREATE TABLE Book
(
bID INT,
bTitle VARCHAR(200),
bPrice DECIMAL,
bAuthor VARCHAR(200),
bQuantity INT,
supplierID INT,
subjectID INT
);
Here is where my site takes the query input
<form action="result.php" method="get" target="resframe">
<label for="query_text">Enter Query:</label>
<input type="text" id="query_text" name="query_text"/>
<input type="submit" name="submit" value="send"/>
</form>
And my result.php actually makes a query to the database here using the following code which works for so far all queries except those using '<' or '>' or a variation of '>=' '<='
$val1 = htmlentities($_GET['query_text']);
$results = mysqli_query($connect, $val1);