За последние 24 часа нас посетили 21433 программиста и 1024 робота. Сейчас ищут 700 программистов ...

Не записывает ничего в MySql

Тема в разделе "PHP для новичков", создана пользователем mrdepser, 23 июн 2019.

Метки:
  1. mrdepser

    mrdepser Новичок

    С нами с:
    23 июн 2019
    Сообщения:
    2
    Симпатии:
    0
    Приветы! Помогите срочно!
    На сервер заливает, а в mysql нет(

    HTML:
    1. <form action="admin.php" method="post" style="width: 100%;
    2.    margin: 0;
    3.    float: left;
    4.    height: 500px" enctype="multipart/form-data">
    5.                 <h4 style="margin: 0; padding: 0">Название:</h4>
    6.                 <input name="name" type="" style="padding: 5px 9px;padding-right: 20px;width: 100%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;"><br>
    7.                 <h4 style="margin: 0; padding: 0">Категория:</h4>
    8.                 <select name="cat"  style="padding: 5px 9px;padding-right: 20px;width: 100%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;">
    9.                     <option value="tv">TV/YouTube</option>
    10.                     <option value="insta">Instagram</option>
    11.                     <option value="stor">Stories</option>
    12.                     <option value="chrom">Chromakey</option>
    13.                 </select>
    14.                 <h4 style="margin: 0; padding: 0">Тип анимации:</h4>
    15.                 <select name="type"  style="padding: 5px 9px;padding-right: 20px;width: 100%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;">
    16.                     <option value="1">Статичный</option>
    17.                     <option value="2">Старт</option>
    18.                     <option value="3">Стандарт</option>
    19.                     <option value="4">Профи</option>
    20.                 </select><br>
    21.                 <br>
    22.                 Цена 10 сек:
    23.                 <input name="price15" style="padding: 5px 9px;padding-right: 20px;width: 35%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;">
    24.                 Цена 15 сек:
    25.                 <input name="price15" style="padding: 5px 9px;padding-right: 20px;width: 35%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;"><br>
    26.  
    27.                 Цена 20 сек:
    28.                 <input name="price20" style="padding: 5px 9px;padding-right: 20px;width: 35%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;">
    29.                 Цена 30 сек:
    30.                 <input name="price30" style="padding: 5px 9px;padding-right: 20px;width: 35%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;"><br><br>
    31.                 Добавить видео:<input name="image" type="file" style="padding: 5px 9px;padding-right: 20px;width: 80%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;"><br><br>
    32.                 <button name="submit" style="padding: 5px 9px;padding-right: 20px;width: 100%;font-family: 'Oxygen', sans-serif;font-size: 1.35em;font-weight: normal;color: #898989;">Добавить</button>
    33.             </form>
    PHP:
    1. <?
    2.   if (isset($_POST['submit'])) {
    3.     $image = $_FILES['image']['name'];
    4.       $image_text = mysqli_real_escape_string($db, $_POST['image_text']);
    5.     $name = mysqli_real_escape_string($db, $_POST['name']);
    6.     $cat = mysqli_real_escape_string($db, $_POST['cat']);
    7.     $type = mysqli_real_escape_string($db, $_POST['type']);
    8.     $price10 = mysqli_real_escape_string($db, $_POST['price10']);
    9.     $price15 = mysqli_real_escape_string($db, $_POST['price15']);
    10.     $price20 = mysqli_real_escape_string($db, $_POST['price20']);
    11.     $price30 = mysqli_real_escape_string($db, $_POST['price30']);
    12.                   // image file directory
    13.       $target = "upload/".basename($image);
    14. $sql = "INSERT INTO order_add (name, cat, type, video, price10, price15, price20, price30) VALUES ('$name', '$cat', '$type', '$image', '$price10', '$price15', '$price20', '$price30')";
    15.       // execute query
    16.       mysqli_query($db, $sql);
    17.  
    18.       if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
    19.           $msg = "Image uploaded successfully";
    20.       }else{
    21.           $msg = "Failed to upload image";
    22.       }
    23.   }?>
    --- Добавлено ---
    Странно что вот этот код записывает.

    PHP:
    1. <?php
    2.   // Create database connection
    3.   $db = mysqli_connect("localhost", "u0697765_default", "sx!cxa2I", "u0697765_api");
    4.  
    5.   // Initialize message variable
    6.   $msg = "yes";
    7.  
    8.   // If upload button is clicked ...
    9.   if (isset($_POST['upload'])) {
    10.       // Get image name
    11.       $image = $_FILES['image']['name'];
    12.       // Get text
    13.       $image_text = mysqli_real_escape_string($db, $_POST['image_text']);
    14.     $name = mysqli_real_escape_string($db, $_POST['name']);
    15.     $desc = mysqli_real_escape_string($db, $_POST['description']);
    16.     $cat = mysqli_real_escape_string($db, $_POST['category']);
    17.     $type_a = mysqli_real_escape_string($db, $_POST['type_a']);  
    18.     $videos = mysqli_real_escape_string($db, $_POST['videos']);  
    19.     $hron10 = mysqli_real_escape_string($db, $_POST['hron10']);
    20.     $hron15 = mysqli_real_escape_string($db, $_POST['hron15']);
    21.     $hron20 = mysqli_real_escape_string($db, $_POST['hron20']);
    22.     $hron30 = mysqli_real_escape_string($db, $_POST['hron30']);
    23.     $hron60 = mysqli_real_escape_string($db, $_POST['hron60']);
    24.     $price10 = mysqli_real_escape_string($db, $_POST['price10']);
    25.     $price15 = mysqli_real_escape_string($db, $_POST['price15']);
    26.     $price20 = mysqli_real_escape_string($db, $_POST['price20']);
    27.     $price30 = mysqli_real_escape_string($db, $_POST['price30']);
    28.     $price60 = mysqli_real_escape_string($db, $_POST['price60']);
    29.  
    30.       // image file directory
    31.       $target = "upload/".basename($image);
    32.  
    33.       $sql = "INSERT INTO services_2 (name, description, photos, videos, category, type_a, hron10, hron15, hron20, hron30, hron60, price10, price15, price20, price30, price60) VALUES ('$name', '$desc', '$image', '$videos', '$cat', '$type_a', '$hron10', '$hron15', '$hron20', '$hron30', '$hron60', '$price10', '$price15', '$price20', '$price30', '$price60')";
    34.       // execute query
    35.       mysqli_query($db, $sql);
    36.  
    37.       if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
    38.           $msg = "Image uploaded successfully";
    39.       }else{
    40.           $msg = "Failed to upload image";
    41.       }
    42.   }
    43.   $result = mysqli_query($db, "SELECT * FROM services_2");
    44. ?>
     
  2. Artur_hopf

    Artur_hopf Активный пользователь

    С нами с:
    7 май 2018
    Сообщения:
    2.266
    Симпатии:
    405
  3. yanuzay

    yanuzay Активный пользователь

    С нами с:
    28 мар 2018
    Сообщения:
    498
    Симпатии:
    57
    Вообще не странно.

    В первом скрипте у тебя нет подключения к базе данных, а во втором есть.
    будь внимательней
     
  4. mrdepser

    mrdepser Новичок

    С нами с:
    23 июн 2019
    Сообщения:
    2
    Симпатии:
    0
    Нет, это не полный код, там впереди есть еще несколько строк и подключение в самом вверху
     
  5. yanuzay

    yanuzay Активный пользователь

    С нами с:
    28 мар 2018
    Сообщения:
    498
    Симпатии:
    57
    какую ошибку выводит mysql ?
     
  6. askanim

    askanim Старожил

    С нами с:
    7 апр 2016
    Сообщения:
    2.201
    Симпатии:
    166
    Адрес:
    GABRIEL
    Действительно странно...
    Да очень, ну очень странно.