I can not understand what is happening error ... The code itself:

$ip=$_SERVER['REMOTE_ADDR']; $id = $_GET['id']; if(isset($id)) { $result = mysql_query ("INSERT INTO rate (id, from, action) VALUES ('$id','$ip','+1')"); if ($result === true) { $text = "Рейтинг истории успешно повышен"; } else { $text = "Ошибка!"; } } else { $text = "Отсутсвует ID"; } 

Displays error

Mistake!

So the problem is in the sql query? There seems to be all right, the table is there, there are columns, it is connected to the database. The id itself accepts.

The very request of the form domen.loc / file.php? Id = idnum

    4 answers 4

    Teach materiel, see the definition of the mysql query function, it returns the resource, not the result of the query. After completing the request, you need to execute the function mysql affected rows to find out that the record really added. See the examples in the documentation for the link.

    ZY and after completing the request, it would be necessary to check if there was an error.

    Enough of this test:

     $text = ($result) ? "Рейтинг истории успешно повышен" : "Ошибка!"; 
      1. Check for field types for DB and what you are trying to write.

      2. table fields in quotes, we use normal library.

          $db=new PDO('$dsn', '$user', '$password'); $req=$db->prepare("INSERT INTO `rate` SET `id`=?, `from`=?, `action`=? " ,array($id,$ip,'+1')); $req->execute(array($table)); 
      • The types of fields varchar (255) about the request, I didn’t quite understand, and even swears at new PDO - rimlin
      • Depending on how you swear, you need to specify the correct data during initialization. In the request, the fields and the table name should be framed with oblique quotes that are located on the keyboard immediately under Esc in the English layout. and the usual request with placeholders - FLK
      • @rimlin, it’s possible that PDO is simply not connected (or compiled without it if you are under Linux). - Oleg Arkhipov

      not so $ result == 'true'

      and $ result === true

      • To sense that, all the same in the database does not insert a record - rimlin
      • 2
        +1 in the action field why? and what type of this field? - vinnie
      • request of the form domen.loc / file.php? id = idnum - rimlin
        if(isset($id)) { $result = mysql_query ("INSERT INTO `rate` (`id` ,`from` ,`action`) VALUES ( '".$id."', '".$ip."', '+1');"); if ($result == true) { $text = "Рейтинг истории успешно повышен"; } 

      How much to write!

      Write you quotes! Is it really that hard? and there would be no question. and the first answer is right instead of === just ==

      • It did not help ... - rimlin
      • > +1 why +1 and not just 1? what's the trick? put there 1 or 0, or 2,3,4,5 what type of field **? INTEGER? if so, the request will never be executed! ** - Artem
      • field varchar (255), can be done and $ 1 result = mysql_query ("INSERT INTO rate (id, from, action) VALUES ('". $ id. ",'". $ ip. "',' 1 ') "); Anyway, it did not help, the record is not inserted. - rimlin
      • Try again, updated the answer. - Artem