0

Working on a database for a school project. I have used the following basic line of PHP code in other parts of my database with success (modified for other tables and values of course):

$sql = "DELETE FROM Rank WHERE RankAbb=" . $_REQUEST["RankAbb"];

Table name is Rank Column name is RankAbb Value in RankAbb is a VARCHAR(10)

This line of code has worked so far on CHAR and INT values.

I have a hyperlinked 'DELETE' button next to each tuple where you should be able to click the link, it references this code, and deletes it from the table.

RankAbb PayGrade FullRank
1stLt O-2 First Lieutenant DELETE EDIT

If I click on the DELETE link I get the following error:

Error: DELETE FROM Rank WHERE RankAbb=1stLt Unknown column '1stLt' in 'where clause'

I've reached my capacity to effectively troubleshoot and decompose the problem. Can anyone help?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
PG_CofC
  • 3
  • 1
  • 2

1 Answers1

4

You need to wrap the value in quotes. This fixes your initial problem. But to avoid problems in the future see Jay Blanchard's comment.

$sql = "DELETE FROM Rank WHERE RankAbb='" . $_REQUEST["RankAbb"] . "'";
slapyo
  • 2,979
  • 1
  • 15
  • 24
  • 3
    Better yet would be to use prepared queries and bound variables. [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 21 '14 at 18:53