-2

When I click on "Add Country", localhost says : Uploading failed, please try again. Can you tell me where is the mistake please ?

<?php

    $db = new mysqli('localhost', 'root', '', 'db');

    if(isset($_POST["submit"]))
    {
        $c_code = addslashes($_POST["c_code"]);
        $c_name = addslashes($_POST["c_name"]);
        $c_key = addslashes($_POST["c_key"]);
        {
          $sql = "insert into countries(country_code, country_name, country_key) values('$c_code', '$c_name', '$c_key')";

          $rs = mysqli_query($db, $sql);

          if($rs)
          {
            echo "<script> alert('Country uploaded successfully') </script>";
          }

          else

          {
            echo "<script> alert('Uploading failed, please try again.') </script>";
          } 
        }
    }


?>

1 Answers1

-1
<?php

$db = new mysqli('localhost', 'root', '', 'db');

if(isset($_POST["submit"]))
{
    $c_code = addslashes($_POST["c_code"]);
    $c_name = addslashes($_POST["c_name"]);
    $c_key = addslashes($_POST["c_key"]);

   //remove this:"{" 

      $sql = "insert into countries(country_code, country_name, country_key) values('$c_code', '$c_name', '$c_key')";

      $rs = mysqli_query($db, $sql);

      if($rs)
      {
        echo "<script> alert('Country uploaded successfully') </script>";
      }

      else

      {
        echo ("Error here:" .mysqli_error($db));
      } 
    }
  //also remove this: "}"
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134