E
E
emerysh2017-06-02 18:32:11
PHP
emerysh, 2017-06-02 18:32:11

Why doesn't mysql database accept php value?

I get the data, decode it, then using foreach I take the values ​​​​by variables and put each one into the database.
But nothing changes in the database.
What is the problem?

THE CODE

<?php

  define('DB_HOST', 'localhost');
  define('DB_USER', 'root');
  define('DB_PASS', '');
  define('DB_NAME', 'prise');
  $conn = mysql_connect(DB_HOST, DB_USER, DB_PASS);
  if (!mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
      exit('Cannot connect to server');
  }
  if (!mysql_select_db(DB_NAME)) {
      exit('Cannot select database');
  }

  mysql_query('SET NAMES utf8');


  function parseCSMONEY(){
  mb_internal_encoding("UTF-8"); 
  $url = 'https://cs.money/load_all_bots_inventory?hash=1496393591316';
  $file = file_get_contents($url);
  $jsondate = json_decode($file, true);
  //echo $file;

  foreach ($jsondate[ponyismylife] as $bot1) {
    $weapon = $bot1['m'];
    $price = $bot1['p'];
    $sql = "INSERT INTO prise (weapon, price) VALUES('$weapon','$price')";
  }
}




if ( isset ($_POST['update']) ) 
{ // нажата кнопка:
  parseCSMONEY();
  echo "обновлено";

}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arman, 2017-06-02
@Arik

You built an INSERT ( $sql ) but you don't send to the DB

J
Janea Morari, 2017-06-02
@gabalugi90

try like this

$sql = mysql_query("INSERT INTO prise (weapon, price) VALUES '$weapon','$price');

A
Artur Bordenyuk, 2017-06-02
@HighQuality

Reconsider your implementation in favor of PDO , it will be more relevant, simpler, clearer and safer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question