Support » Fixing WordPress » sql error

  • Hi Guys

    I keep getting errors when executing the following query:

    $wpdb->get_row(“SELECT * FROM alb_teachers WHERE teacher_name = $teacher_name”);

    WordPress database 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 ‘Abaa Alay’ at line 1]
    SELECT * FROM alb_teachers WHERE teacher_name = Abaa Alay

    Here is the DB table:

    CREATE TABLE alb_teachers (
    teacher_id integer auto_increment NOT NULL,
    teacher_name varchar(120) NOT NULL,
    teacher_description text NULL,
    PRIMARY KEY(teacher_id)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your teacher_name needs to be in quotes. I believe this will work:

    $wpdb->get_row("SELECT * FROM alb_teachers WHERE teacher_name = '$teacher_name'");

    Thanks. BTW, does WP offer transaction committ and rollback ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sql error’ is closed to new replies.