Gives an error on request

I can’t figure out what the error is… The code itself:

$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 an error


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

The request itself like domen.loc/file.php?id=idnum

Answer 1, authority 100%

Learn the materiel, see the function definition mysql query, it returns a resource, not the result of a query. After executing the query, you need to execute the function mysql affected rowsto see if the entry was actually added. See the examples in the documentation at the link.

Z.Y. and after executing the request, it would be necessary to check if there was an error.

The following test is sufficient:

$text = ($result) ? "   " : "!";

Answer 2

  1. Check for field types for the database and what you are trying to write.

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

    $db=new PDO('$dsn', '$user', '$password');
     $req=$db->prepare("INSERT INTO `rate` SET `id`=?, `from`=?, `action`=? "     

Answer 3

not so
$result == ‘true’

and so
$result === true

Answer 4

   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 QUOTATION MARKS! is it really so difficult? and there would be no question. and the first responder is right instead of ===just ==

Leave a reply

Please enter your comment!
Please enter your name here