/home/awneajlw/public_html/codestechvista.com/save-shop-data.php
<?php
session_start();
require_once 'config/database.php';
require_once 'includes/auth.php';
$database = new Database();
$db = $database->getConnection();
// Get the latest user ID (for demo purposes)
$query = "SELECT id FROM users ORDER BY id DESC LIMIT 1";
$stmt = $db->prepare($query);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$user_id = $user['id'];
// Get form data
$whatsapp = sanitizeInput($_POST['whatsapp'] ?? '');
$facebook = sanitizeInput($_POST['facebook'] ?? '');
$instagram = sanitizeInput($_POST['instagram'] ?? '');
$website = sanitizeInput($_POST['website'] ?? '');
// Update shop data with social media information
$query = "UPDATE shops SET
shop_phone = ?,
shop_description = CONCAT(IFNULL(shop_description, ''),
IF(shop_description IS NOT NULL AND shop_description != '', '\n\n', ''),
'Social Media:\n',
'WhatsApp: ', ?, '\n',
'Facebook: ', ?, '\n',
'Instagram: ', ?, '\n',
'Website: ', ?)
WHERE user_id = ?";
$stmt = $db->prepare($query);
$success = $stmt->execute([
$whatsapp,
$whatsapp,
$facebook,
$instagram,
$website,
$user_id
]);
if ($success) {
// Set user as logged in
$_SESSION['user_id'] = $user_id;
$_SESSION['role'] = 'shop_owner';
// Redirect to home page
header('Location: home.php');
exit();
} else {
// Error occurred
header('Location: social-media-reg.php?error=1');
exit();
}
?>