nouamane18 nouamane18 - 3 years ago 140
PHP Question

Uploading failed, please try agin

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>";
}
}
}


?>

Answer Source
<?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: "}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download