G
G
givier2020-06-25 02:06:31
PHP
givier, 2020-06-25 02:06:31

Why does he not want to pull data from the database or does the variable not work?

<?php
    $host = 'localhost';  // Хост, у нас все локально
    $user = 'test1';    // Имя созданного вами пользователя
    $pass = 'testtest11122'; // Установленный вами пароль пользователю
    $db_name = 'user1213408_test';   // Имя базы данных
    $link = mysqli_connect($host, $user, $pass, $db_name); // Соединяемся с базой

    // Ругаемся, если соединение установить не удалось
    if (!$link) {
      echo 'Не могу соединиться с БД. Код ошибки: ' . mysqli_connect_errno() . ', ошибка: ' . mysqli_connect_error();
      exit;
    }	
?>
<?php
   if (isset($_GET['id'])) {
      $sql = mysqli_query($link, "SELECT `ID`, `Name`, `Price`, `Nickname` FROM `product` WHERE `ID`={$_GET['id']}");
      $product = mysqli_fetch_array($sql);
    $order_id = isset($_GET['id']) ? $product['ID'] : ''; 
    $description = isset($_GET['id']) ? $product['Name'] : '';
    $amount = isset($_GET['id']) ? $product['Price'] : '';  
    $login = isset($_GET['id']) ? $product['Nickname'] : ''; 
   }
?>

variables
<?=$amount;?>
" . $login . "

I don't get anything I
would be grateful for any hint

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2020-06-25
@givier

one)

WHERE `ID`={$_GET['id']}
for this, in a decent society, they beat the clave on the kumpol, until complete enlightenment.
2) there is an important function that for some reason all beginners ignore - var_dump(); 100% solves problems, the main thing is to use it correctly and often.
3) If there is a request and there is a problem with its use - display the request (as a string) and run this request "manually", for example, through phpmyadmin.
4) Wang that the output of errors and warnings is turned off for you. See logs or turn on error output.

S
Seva Shpun, 2020-06-25
@SevaShpun

To work with the database, I highly recommend using RedBeanPHP ORM . Very good and handy item.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question