SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Wan's Avatar
    Join Date
    Sep 2004
    Location
    kl
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Syntax error (missing operator) in query expression

    Hello again. I have 4 page & 4 tbl record. So 1 page is for 1 tbl. All those 4 page post to 1 another page that used to delete record. This is the code.
    <%
    Dim sSQL, sConnString, Conn, jenis, data
    jenis = Request.Form("jenis")
    data = Request.Form("data")

    SELECT CASE jenis
    Case "peralatan"
    sSQL = "DELETE * FROM peralatan WHERE peralatan = " & data

    Case "perisian"
    sSQL = "DELETE * FROM perisian WHERE perisian = " & data

    Case "jabatan"
    sSQL = "DELETE * FROM jabatan WHERE jabatan = " & data

    Case "pegawai"
    sSQL = "DELETE * FROM pegawai WHERE pegawai = " & data

    END SELECT

    sConnString = "PROVIDER=MICROSOFT.Jet.OLEDB.4.0;" & _
    "Data Source = " & Server.MapPath("sistem.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open(sConnString)
    Conn.Execute(sSQL)
    Conn.Close
    Set Conn = Nothing

    Response.write data &" <p align='center'><b><font color='#8A3871'> telah dipadamkan dari rekod.</font></b></p>"
    Response.write "<p align='center'><b><font color='#8A3871'>Sila klik butang dibawah untuk ke halaman admin.</font></b></p>"
    %>
    For information, there has 2 value submitted from the 4 page. when i try response.write jenis&data it show the value submitted. But it giving error message at Conn.execute(sSQL). I dont know well what im doing wrong here. Wish someone could help me.
    Last edited by Wan; Sep 22, 2004 at 00:30.

  2. #2
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DELETE tablename WHERE fieldname = 'value'

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You're supposed to wrap strings around single quotes in SQL. Also, why the select case statement? This would be much more efficient:
    Code:
    <%
    Dim sSQL, sConnString, Conn, jenis, data
    jenis = Request.Form("jenis")
    data = Request.Form("data")
    
    sSQL = "DELETE FROM pegawai WHERE " & jenis & "='" & data & "';"
    
    sConnString = "PROVIDER=MICROSOFT.Jet.OLEDB.4.0;" & _
    "Data Source = " & Server.MapPath("sistem.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open(sConnString)
    Conn.Execute(sSQL)
    Conn.Close
    Set Conn = Nothing
    
    Response.write data &" <p align='center'><b><font color='#8A3871'> telah dipadamkan dari rekod.</font></b></p>"
    Response.write "<p align='center'><b><font color='#8A3871'>Sila klik butang dibawah untuk ke halaman admin.</font></b></p>"
    %>
    The part in red is what I changed for efficiency and correctness .

    And as tjsaynor said, you don't need the * in a DELETE statement.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •