php 我应该写什么代码,以便在我的股票跟踪盈亏网站上打开和关闭登录时不会从屏幕上删除数据?[已关闭]

k3bvogb1  于 10个月前  发布在  PHP
关注(0)|答案(1)|浏览(71)

**已关闭。**此问题需要debugging details。它目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
4天前关闭。
Improve this question


的数据
如何确保在退出和进入时不删除下面添加的产品部分?第一个月
我已经尝试了3个小时来运行代码,我快要疯了,我找不到太多的资源,我搜索

<?php
// Veritabanı bağlantısı için gerekli bilgileri ayarlayın
$servername = "localhost"; // Sunucu adı (genellikle "localhost")
$username = "root"; // Veritabanı kullanıcı adı
$password = ""; // Veritabanı şifresi
$dbname = "savedata"; // Veritabanı adı

// Veritabanına bağlantı oluşturun
$conn = new mysqli($servername, $username, $password, $dbname);

// Bağlantıyı kontrol edin
if ($conn->connect_error) {
    die("Veritabanı bağlantısı başarısız: " . $conn->connect_error);
}

// Oturumu başlatın
session_start();

// Oturumda giriş yapan kullanıcının adını alın
$username = isset($_SESSION['username']) ? $_SESSION['username'] : 'Misafir';

// Formdan gelen verileri alın
$marka = isset($_POST['marka']) ? $_POST['marka'] : '';
$seri = isset($_POST['seri']) ? $_POST['seri'] : '';
$model = isset($_POST['model']) ? $_POST['model'] : '';
$yil = isset($_POST['yil']) ? $_POST['yil'] : '';
$km = isset($_POST['km']) ? $_POST['km'] : '';
$alis = isset($_POST['alis']) ? $_POST['alis'] : '';
$masraf = isset($_POST['masraf']) ? $_POST['masraf'] : '';
$tahminiSatis = isset($_POST['tahminiSatis']) ? $_POST['tahminiSatis'] : '';

$expertizRaporu = isset($_FILES['expertizRaporu']['tmp_name']) ? $_FILES['expertizRaporu']['tmp_name'] : '';
$carPhotos = isset($_FILES['photos']['tmp_name']) ? $_FILES['photos']['tmp_name'] : [];

if (is_array($carPhotos)) {
    foreach ($carPhotos as $index => $photo) {
        // Fotoğraf yükleme işlemleri
    }
}


// Dosy  yollarını hedef klasöre taşıyın (örn. "uploads" klasörü)
$expertizRaporuPath = "uploads/expertiz_" . $username . "_" . time() . ".jpg";
$carPhotosPath = [];
foreach ($carPhotos as $index => $photo) {
    $carPhotosPath[$index] = "uploads/carphoto_" . $username . "_" . time() . "_$index.jpg";
    move_uploaded_file($photo, $carPhotosPath[$index]);
}

// SQL sorgusunu oluşturun ve verileri veritabanına ekleyin
$sql = "INSERT INTO urunler (marka, seri, model, yil, km, alis, masraf, tahmini_satis, expertiz_raporu, car_photos)
        VALUES ('$marka', '$seri', '$model', '$yil', '$km', '$alis', '$masraf', '$tahminiSatis', '$expertizRaporuPath', '" . implode(',', $carPhotosPath) . "')";

// Sorguyu çalıştırın
if ($conn->query($sql) === TRUE) {
    echo "Yeni ürün başarıyla eklendi.";
} else {
    echo "Hata: " . $sql . "<br>" . $conn->error;
}

// Veritabanı bağlantısını kapatın
$conn->close();
?>


<!DOCTYPE html>
<html>
<head>
    <title>Stok Takip</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="takip.css">
    
</head>
<body>

<a href="logout.php" class="btn btn-primary">Çıkış Yap</a>

    <div class="container">
        <h1><?php
            // Oturumu başlat ve giriş yapan kullanıcının adını al
            
            if (isset($_SESSION['username'])) {
                echo $_SESSION['username'];
            }
        ?></h1>

        

        <form id="urunForm" method="POST" action="">
              
            <div class="form-group">
                <label for="photos">Araba Fotoğrafları:</label>
                <input type="file" name="photos" id="photos" accept="image/*" multiple>
            </div>

            <div class="form-group">
                <label for="marka">Marka:</label>
                <select name="marka" id="marka" required>
                    <option value="">Seçiniz</option>
                </select>
            </div>

            <div class="form-group">
                <label for="seri">Seri:</label>
                <select name="seri" id="seri" required>
                    <option value="">Seçiniz</option>
                </select>
            </div>



            <div class="form-group">
                <label for="model">Model:</label>
                <input type="text" name="model" id="model" required>
            </div>

          

           

            <div class="form-group">
                <label for="yil">Yıl:</label>
                <input type="number" name="yil" id="yil" min="1980" max="2025" required>
            </div>

            <div class="form-group">
                <label for="km">KM:</label>
                <input type="text" name="km" id="km" pattern="[0-9]*" inputmode="numeric" required>
            </div>

            <div class="form-group">
                <label for="expertizRaporu">Expertiz Raporu:</label>
                <input type="file" name="expertizRaporu" id="expertizRaporu" accept="image/*" required>
            </div>

            <div class="form-group">
                <label for="alis">Alış (TL):</label>
                <input type="text" name="alis" id="alis" pattern="[0-9]*" inputmode="numeric" required>
            </div>

            <div class="form-group">
                <label for="masraf">Masraf (TL):</label>
                <input type="text" name="masraf" id="masraf" pattern="[0-9]*" inputmode="numeric" required>
            </div>

            <div class="form-group">
                <label for="tahminiSatis">Tahmini Satış (TL):</label>
                <input type="text" name="tahminiSatis" id="tahminiSatis" pattern="[0-9]*" inputmode="numeric" required>
            </div>

            <input type="submit" value="Ekle" class="btn btn-primary mt-3">

        </form>

            
        <form id="urunForm" method="POST" action="ekle.php" enctype="multipart/form-data">
    <!-- Form içeriği burada olacak -->
</form>

        <table id="urunListesi">
    <tr>
        <th>Marka</th>
        <th>Seri</th>
        <th>Model</th>
        <th>Yıl</th>
        <th>KM</th>
        <th>Expertiz Raporu</th>
        <th>Alış (TL)</th>
        <th>Masraf (TL)</th>
        <th>Tahmini Satış (TL)</th>
        <th>Net Kar (TL)</th>
        <th>Araba Fotoğrafları</th>

    
   
    </tr>
          </table>

        <div id="carPhotosModal" class="modal" tabindex="-1">
            <div class="modal-dialog modal-dialog-centered">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Araba Fotoğrafları</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body" id="carPhotosBody">
                        <div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
                            <div class="carousel-inner" id="carouselInner">
                                <!-- Car photos will be displayed here -->
                            </div>
                            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
                                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                                <span class="visually-hidden">Previous</span>
                            </button>
                            <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
                                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                                <span class="visually-hidden">Next</span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
      
    

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Ürünleri tutmak için boş bir dizi oluşturuyoruz
        var urunler = [];
        var carPhotos = [];
        var carBrands = [
        "Alfa Romeo",  "Aston Martin",  "Audi", "Bentley",  "BMW", 
        "Bugatti", "Buick",  "Cadillac",  "Chery",   "Chevrolet",
         "Chrysler",  "Citroen", "Dacia",  "Daewoo",  "Daihatsu", 
        "Dodge",  "Ferrari", "Fiat", "Ford", "Geely",  "Honda", 
        "Hyundai",  "Infiniti","Isuzu",  "Iveco",  "Jaguar",  "Jeep",
        "Kia",  "Lada", "Lamborghini", "Lancia",  
        "Land-rover", "Lexus",  "Lincoln",  "Lotus",  "Maserati", 
        "Mazda", "McLaren",  "Mercedes-Benz",  "Mini",  "Mitsubishi", 
        "Nissan",  "Opel", "Peugeot",  "Porsche", "Proton",  
        "Renault", "Rolls Royce",  "Rover", "Saab", "Seat",  "Skoda", 
        "Smart", "Ssangyong",  "Subaru",  "Suzuki", , "Tata",  ,
        "Tofaş",  "Toyota",  "Volkswagen", "Volvo", 
    ];

        
    var carModels = {
            "Alfa Romeo": ["Giulietta", "Stelvio", "Giulia", "4C", "8C"],
            "Aston Martin": ["Vantage", "DB11", "DBS", "DBX", "Valhalla"],
            "Audi": ["A1", "A3", "A4", "A5", "A6", "A7", "A8", "Q2", "Q3", "Q5", "Q7", "Q8", "TT", "R8"],
            "Bentley": ["Bentayga", "Continental GT", "Flying Spur", "Mulsanne"],
            "BMW": ["1 Serisi", "2 Serisi", "3 Serisi", "4 Serisi", "5 Serisi", "6 Serisi", "7 Serisi", "8 Serisi", "X1", "X2", "X3", "X4", "X5", "X6", "X7", "Z4", "i3", "i8"],
            "Mercedes-Benz": ["A Serisi", "B Serisi", "C Serisi", "E Serisi", "S Serisi", "CLA", "CLS", "GLA", "GLC", "GLE", "GLS", "AMG GT", "EQC"],
            "Citroen": ["C1", "C3", "C3 Aircross", "C4", "C4 Cactus", "C4 Picasso", "C5", "C5 Aircross"],
            "Dacia": ["Sandero", "Logan", "Duster", "Sander Stepway", "Duster Stepway", "Lodgy"],
            "Honda": ["Civic", "Accord", "CR-V", "HR-V", "Jazz", "Civic Type R"],
            "Hyundai": ["i10", "i20", "i30", "i40", "ix20", "ix35", "Tucson", "Santa Fe"],
            "Isuzu": ["D-Max", "MU-X"],
            "Jeep": ["Renegade", "Compass", "Cherokee", "Grand Cherokee", "Wrangler"],
            "Fiat": ["Egea", "Fiorino", "Linea", "Panda", "500", "Tipo", "Doblo", "500X", "500L"],
            "Ford": ["Fiesta", "Focus", "Fusion", "Mondeo", "EcoSport", "Kuga", "Edge", "Mustang", "Puma"],
            "Renault": ["Clio", "Megane", "Symbol", "Fluence", "Captur", "Kadjar", "Talisman", "Koleos", "Zoe", "Arkana"],
            "Nissan": ["Micra", "Note", "Juke", "Qashqai", "X-Trail", "Leaf"],
            "Opel": ["Corsa", "Astra", "Insignia", "Mokka", "Grandland", "Crossland"],
            "Peugeot": ["208", "308", "301", "2008", "3008", "5008", "Bipper", "Rifter", "Traveller"],
            "Seat": ["Ibiza", "Leon", "Toledo", "Ateca", "Arona", "Tarraco"],
            "Skoda": ["Fabia", "Octavia", "Rapid", "Scala", "Karoq", "Kodiaq", "Superb", "Citigo"],
            "Suzuki": ["Swift", "Vitara", "SX4 S-Cross", "Jimny"],
            "Subaru": ["Impreza", "Legacy", "XV", "Outback", "Forester"],
            "Toyota": ["Yaris", "Corolla", "Auris", "C-HR", "Rav4", "Camry", "Prius", "Supra"],
            "Volkswagen": ["Polo", "Golf", "Passat", "Tiguan", "Touareg", "T-Roc", "Up", "Arteon", "ID.3"],
            "Volvo": ["S60", "S90", "V60", "V90", "XC40", "XC60", "XC90"]
        };


        // Form gönderildiğinde çalışacak işlev
        document.getElementById("urunForm").addEventListener("submit", function(event) {
            event.preventDefault(); // Formun varsayılan davranışını engelliyoruz
                
            var photosInput = document.getElementById("photos");
        var photos = photosInput.files;
        
        for (var i = 0; i < photos.length; i++) {
            carPhotos.push(photos[i]);
        }

        photosInput.value = "";
            // Formdaki verileri alıyoruz
            var marka = document.getElementById("marka").value;
            var model = document.getElementById("model").value;
            var yil = document.getElementById("yil").value;
            var km = document.getElementById("km").value;
            var expertizRaporu = document.getElementById("expertizRaporu").files[0];
            var alis = parseFloat(document.getElementById("alis").value.replace(',', '.'));
            var tahminiSatis = parseFloat(document.getElementById("tahminiSatis").value.replace(',', '.'));

            // Yeni ürün nesnesi oluşturuyoruz
            var yeniUrun = {
                marka: marka,
                model: model,
                yil: yil,
                km: km,
                expertizRaporu: expertizRaporu,
                alis: alis,
                tahminiSatis: tahminiSatis
            };

            // Yeni ürünü diziye ekliyoruz
            urunler.push(yeniUrun);

            // Tabloya yeni ürünü ekliyoruz
            var masraf = parseFloat(document.getElementById("masraf").value.replace(',', '.'));

// Calculate Net Kar (Profit)
var netKar = tahminiSatis - alis - masraf;
var seriSelect = document.getElementById("seri"); // Seri select elementini alıyoruz
var seri = seriSelect.value;
// Display the values in the table
var urunListesiTablosu = document.getElementById("urunListesi");
        var yeniSatir = urunListesiTablosu.insertRow();
        var hucreMarka = yeniSatir.insertCell();
        var hucreSeri = yeniSatir.insertCell();  
        var hucreModel = yeniSatir.insertCell();
        var hucreYil = yeniSatir.insertCell();
        var hucreKm = yeniSatir.insertCell();
        var hucreExpertizRaporu = yeniSatir.insertCell();
        var hucreAlis = yeniSatir.insertCell();
        var hucreMasraf = yeniSatir.insertCell(); // Initialize hucreMasraf
        var hucreTahminiSatis = yeniSatir.insertCell();
        var hucreNetKar = yeniSatir.insertCell(); // Initialize hucreNetKar
        var hucreCarPhotos = yeniSatir.insertCell(); // Initialize hucreCarPhotos

        hucreMarka.innerHTML = marka;
        hucreSeri.innerHTML = seri;
        hucreModel.innerHTML = model;
        hucreYil.innerHTML = yil;
        hucreKm.innerHTML = km;
        hucreExpertizRaporu.innerHTML = "<img src='" + URL.createObjectURL(expertizRaporu) + "' width='100' alt='Expertiz Raporu'>";
        hucreAlis.innerHTML = alis.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&.') + " TL";
        hucreMasraf.innerHTML = masraf.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&.') + " TL";
        hucreTahminiSatis.innerHTML = tahminiSatis.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&.') + " TL";
        hucreNetKar.innerHTML = netKar.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&.') + " TL"; // Adding Net Kar to the table
        
        // Add a click event to display the car photos in a modal
        hucreCarPhotos.innerHTML = "<a href='#' onclick='showCarPhotos(" + (urunler.length - 1) + ")'>Görüntüle</a>";
    });

    // Function to show car photos in the modal
    function showCarPhotos(index) {
        var modalBody = document.getElementById("carouselInner");
        modalBody.innerHTML = "";

        carPhotos.forEach(function(photo, i) {
            var img = document.createElement("img");
            img.src = URL.createObjectURL(photo);
            img.className = i === index ? "carousel-item active" : "carousel-item";
            img.alt = "Car Photo " + (i + 1);
            modalBody.appendChild(img);
        });

        var myModal = new bootstrap.Modal(document.getElementById("carPhotosModal"));
        myModal.show();
    
        };

        function updateCarBrandList() {
            var markaSelect = document.getElementById("marka");
            markaSelect.innerHTML = "<option value=''>Seçiniz</option>";

            carBrands.forEach(function(brand) {
                var option = document.createElement("option");
                option.value = brand;
                option.textContent = brand;
                markaSelect.appendChild(option);
            });
        }

function updateCarModels() {
            var markaSelect = document.getElementById("marka");
            var modelSelect = document.getElementById("seri");
            var selectedBrand = markaSelect.value;

            // Clear previous options
            modelSelect.innerHTML = "<option value=''>Seçiniz</option>";

            if (selectedBrand !== "") {
                // Get models for the selected brand
                var models = carModels[selectedBrand];

                // Add models as options
                models.forEach(function (model) {
                    var option = document.createElement("option");
                    option.value = model;
                    option.textContent = model;
                    modelSelect.appendChild(option);
                });
            }
        }

        document.getElementById("marka").addEventListener("change", updateCarModels);
        updateCarBrandList();

    </script>
    
</body>
</html>

字符串
当我使用php连接到数据库并登录和退出时,它会将其打印回屏幕,但我不能。

hpcdzsge

hpcdzsge1#

在不登录的情况下存储临时数据可以使用setcookie函数
https://www.php.net/manual/en/function.setcookie.php#103629

相关问题