0
votes

i get this error when i try to add info into database: ошибка:

INSERT INTO `paper` (`PaperPrice`, `paperType`) VALUES (`666`, `PAPERBLA`)

Unknown column '666' in 'field list' Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\OpenServer\domains\localhost\menu.php on line 49

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\OpenServer\domains\localhost\menu.php on line 49 Access denied for user 'ODBC'@'localhost' (using password: NO)

666 and PAPERBLA have to be added into column, but it writes that tehre is no column '666', this is my php code:

     $table = 'paper';
     $PriceTable = 'paperPrice';
     $priceColumn = 'PaperPrice';
     $typeColumn = 'paperType';
     $host = 'localhost';
     $username = 'root';
     $password = '';
     $dbname = 'info';

      // Create connection
       $conn = mysqli_connect($servername, $username, $password, $dbname);
          // Check connection
       if (!$conn) {
            die("<table border='1'><tr><td>Connection failed: </td></tr>" . mysqli_connect_error());
    }else{
echo"<table border='1'><tr><td>Connection success </td></tr>";
  }


      if(isset($_POST['submit'])){

       $paperType = $_POST['t1'];
    $paperRemove = $_POST['t2'];
      $paperPrice = $_POST['t3'];

       if($paperRemove=='' && $paperType!=''){
    $sql = "INSERT INTO `$table` (`$priceColumn`, `$typeColumn`) VALUES (`$paperPrice`, `$paperType`)";

      if (mysqli_query($conn, $sql)) {
 echo 'добавлено "'.$paperType.'" в список" "'.$table.'"';
    } else {
       echo "ошибка: " . $sql . "<br>" . mysqli_error($conn);
     }
          }
1
we don't use tick (`) on the values.... use quotes instead.. and the error is about your connection credential... - Sam Teng Wong

1 Answers

2
votes

You are using backticks with values. Backticks are used for identifiers.

"INSERT INTO `$table` (`$priceColumn`, `$typeColumn`) VALUES (`$paperPrice`, `$paperType`)"

You have to use 's for strings -

"INSERT INTO `$table` (`$priceColumn`, `$typeColumn`) VALUES ($paperPrice, '$paperType')"

Help