Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2002
    Location
    New York
    Posts
    791

    plz look over my code

    Hello my code is not working anyone spot an error??
    The error I get says
    Parse error: parse error, unexpected T_VARIABLE line 15
    which is this line
    $sql = "DELETE FROM customers WHERE id = '$id'";

    here is my code
    include("include/db_config.php")
    $db = mysql_connect("$server","$user","$password");
    mysql_select_db ($database);
    $id = $_GET['id'];
    $sql = "DELETE FROM customers WHERE id = '$id'";
    $result = mysql_query($sql, $db);
    echo "Customer deleted!";


    I have a page that calls all the lastnames in the database with their associated id and a link to the delete page that looks like this
    <a href=delete.php?id=$id>delete</a>

    on my delete page in the address bar I see it does have the correct $id number shown but the page still has an error

    o

  2. #2
    Could it be the single quotes within the double quotes? Try escaping it like this:

    $sql = "DELETE FROM customers WHERE id = \'$id\'";

    Actually, it may not need quotes at all. When making a comparison to another variable, I've never had to quote around the variable and just do something like: WHERE id = $id

  3. #3
    Join Date
    Feb 2002
    Location
    New York
    Posts
    791
    No still get the same error ??
    and I can not fine whats wrong :-(

  4. #4
    Join Date
    Jan 2005
    Location
    Baghdad, Iraq
    Posts
    172
    You'll not believe this ... but just take a look at this line:
    PHP Code:
    include("include/db_config.php"
    There is no semicolon ... put ; and the code will work
    regards
    The Dream is the blueprint of success, the hope is the budget and hard working is the achievement

  5. #5
    Join Date
    Feb 2002
    Location
    New York
    Posts
    791
    ok so my code is:

    include("include/db_config.php");
    $db = mysql_connect("$server","$user","$password");
    mysql_select_db ($database);
    $id = $_GET['id'];
    $sql = "DELETE FROM customers WHERE id = $id";
    $result = mysql_query($sql, $db);
    echo "Customer deleted!";

    I know get an error that says
    Parse error: parse error, unexpected $ line 26 which is a blank line outside of my ?> tag

    so not sure what line the actual error is on?

  6. #6
    Join Date
    Jan 2005
    Location
    Baghdad, Iraq
    Posts
    172
    Check your code braces, there should be a non-closed brace.
    The Dream is the blueprint of success, the hope is the budget and hard working is the achievement

  7. #7
    Join Date
    Feb 2002
    Location
    New York
    Posts
    791
    DOHHH!!

    LOL thanks that fixed it

  8. #8
    Editing: just saw that you fixed your problem.

  9. #9
    Join Date
    Feb 2002
    Location
    New York
    Posts
    791
    ya I fixed it

    I was just missing a

    }

    at the end of my page

    thanks all for your help

Posting Permissions

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