Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialzhuoyu zhu
9,806 PointsNumeric type attribute value within SQL query
Hi,
I am working on my personal project that is relevant to this video. However, I encounter an error when I tried to pass a numeric attribute value within SQL query.
Here is the example: <input type="number" id="lmax" name="numberOfItem"> $numberOfItem = trim($_REQUEST['numberOfItem']);
$results = $db->query("SELECT title, numberOfItem FROM Media where numberOfItem > $numberOfItem");
Results: When I first load my page, it give me this error: "Query failed: 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 '' at line 1".
In addition, when I enter a number for $numberOfItem like 5, the error disappear but it returns nothing which doesn't make sense since I have valid data within my server.
Any ideas? I am new to PHP.
Thanks a lot.
1 Answer
Waqar Mohammad
2,914 Points$numberOfItem - I think this variable is causing the issue. It works with a number because the syntax is right. I don't understand why you are putting a variable there?
Instead of numberOfItem, can you use the Count function?