Announcement

Collapse
No announcement yet.

Another silly one

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Another silly one

    Thanks to Flesso I got the other bits sorted but have stubled at this hurdle. I want to delete stuff from the DB using php.

    Code:
    $sql="DELETE FROM table1 WHERE name=$name AND WHERE tel=$tel";
    $result = mysql_query($sql);
    This is what I have but it fails to delete..... I know thw values of $name and $tel are being passed in cos I did a print $sql and it looked right..

    Any clues.

    Thanks
    Ash

  • #2
    Originally posted by comports View Post
    Thanks to Flesso I got the other bits sorted but have stubled at this hurdle. I want to delete stuff from the DB using php.

    Code:
    $sql="DELETE FROM table1 WHERE name=$name AND WHERE tel=$tel";
    $result = mysql_query($sql);
    This is what I have but it fails to delete..... I know thw values of $name and $tel are being passed in cos I did a print $sql and it looked right..

    Any clues.

    Thanks
    Ash
    Try something like:

    PHP Code:
    $query  'DELETE FROM Table WHERE Name =' $name
    So...

    PHP Code:
    $sql 'DELETE FROM table1 WHERE name = ' $name 'AND tel = ' $tel
    Just a try, as I said previously, I'm no expert....

    Comment


    • #3
      Flesso is right. You added a WHERE clause near the end of your statement:

      AND WHERE tel=$tel";
      If you want to add clauses for 2 things, as you did, you use AND only; so another WHERE is not necessary, rather incorrect.

      Cocatenation operators (.) to seperate two strings as flesso has quoted to you may not be required for variables, but certainly required for functions and variables that are mysql_fetch_object() results, etc.

      And don't forget, when you're querying values for specific fields, etc., as flesso has done so, you add single-quotations, like:

      DELETE FROM table1 WHERE username = '$var'
      Correction:

      $sql = "DELETE FROM table1 WHERE name = '$name' AND tel = '$tel'";
      // then query the variable
      Visiting the PHP.net and MySQL.com documentation helps .

      PHP: Hypertext Preprocessor
      MySQL :: The world's most popular open source database
      Last edited by Ben Stones; 21-08-2008, 07:15.

      Comment

      Working...
      X