-1

I try to update a row in my database. i receive no error but the update does not happend

$sql = "UPDATE calendar_events 
        SET event_title='".$_POST["naam"]."' 
        WHERE id ='($event_id)'";

problem is by variable $event_id. If i place a nummber in place of $event_id ( WHERE id =6) then it is ok and i have my update but any he do not accept any variable I did change a lot of things. The type of variabls id and $event_id are the same. De value of the id and $event_id are de same . i did try with $event_id, and '".$event_id."'. every thing is ok and no erroror from database bat the update do not happen. can someone help me thanks

ComFreek
  • 29,044
  • 18
  • 104
  • 156
chehr
  • 19
  • 4
  • 2
    And of course please filter your naam before entering it into the sql string! – ToBe Nov 14 '13 at 16:28
  • Try printing the sql onscreen, and if the sql is correct, execute it on the Database you are working on, to see if the query is correct for the database. – Juan Garcia Nov 14 '13 at 16:29
  • What is the type of the id column? – Juan Garcia Nov 14 '13 at 16:30
  • 1
    Use `WHERE id = '$event_id' ";` instead. Parentheses are mostly used when there is more than one value. Plus, using `'".$_POST["naam"]."'` is not considered a safe calling method. – Funk Forty Niner Nov 14 '13 at 16:30
  • I also noticed in [your other question](http://stackoverflow.com/questions/19957009/update-the-single-row-in-php-row-with-php) that you are using `MySQL_` - I strongly suggest that you move over to `MySQLi_` or PDO. Mostly for security reasons. Your site/DB stands at being hacked if you continue using this method. – Funk Forty Niner Nov 14 '13 at 16:37

1 Answers1

0

Try with

$sql = "UPDATE calendar_events 
        SET event_title='".$_POST["naam"]."' 
         WHERE id ='$event_id'";

Otherwise, you are comparing it with (1), (2) or whatever number it has, but with parenthesis.

UPDATE: and, of course, SANITIZE your $_POST variables!!!

opalenzuela
  • 3,139
  • 21
  • 41