FSCash/html/save_symbol.php

45 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require 'config.php';
header('Content-Type: application/json');
// JSON-Input einlesen
$data = json_decode(file_get_contents('php://input'), true);
$id = $data['id'] ?? null;
$symbol = $data['symbol'] ?? null;
// Input validieren
if (!$id || !$symbol) {
echo json_encode([
'success' => false,
'message' => 'Ungültige Eingabedaten.'
]);
exit;
}
try {
$stmt = $pdo->prepare("UPDATE aktien SET Symbol = :symbol WHERE id = :id AND user_id = :userid");
$stmt->execute([
'symbol' => $symbol,
'id' => $id,
'userid' => $_SESSION['user_id']
]);
// Prüfen, ob ein Datensatz tatsächlich aktualisiert wurde
if ($stmt->rowCount() > 0) {
echo json_encode([
'success' => true,
'symbol' => $symbol,
'message' => "Symbol erfolgreich gespeichert: $symbol"
]);
} else {
echo json_encode([
'success' => false,
'message' => 'Keine Änderung – evtl. ID existiert nicht oder gehört nicht zum Benutzer.'
]);
}
} catch (PDOException $e) {
echo json_encode([
'success' => false,
'message' => 'Datenbankfehler: ' . $e->getMessage()
]);
}