fitness-api/html/api/add_exercise_to_workout.php

29 lines
1.1 KiB
PHP

<?php
include "../../config.php";
if (isset($_GET['token'])){
$sql = "SELECT * FROM tokens INNER JOIN users ON users.id=tokens.user WHERE token=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_GET['token']);
if ($stmt->execute()){
if ($stmt->rowCount() == 1){
if(isset($_POST['workout']) and isset($_POST['exercise']) and isset($_POST['amount']) and isset($_POST['sets'])){
$sql = "INSERT INTO `exercises_in_workout`(`workout_routine`, `workout_type`, `amount`, `sets`) VALUES (?,?,?,?)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_POST['workout']);
$stmt->bindParam(2, $_POST['exercise']);
$stmt->bindParam(3, $_POST['amount']);
$stmt->bindParam(4, $_POST['sets']);
if ($stmt->execute()){
echo 'success';
}else{
var_dump($stmt->errorInfo());
}
}else{
echo "missing parameters";
}
}else{
echo 'login failed';
}
}
}