0

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... Commented Mar 3, 2016 at 5:54

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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)
bro, thats ok, its working :d i will accept ur nswer in 5 minutes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.