PHPコードは、(例えばWeightUnit 1及び2.2に設定)されているだけWeightUnitのどんな「値を」を挿入し、フィールドを選択TIMEUNIT。あなたのページ/コードが何をしているのか分かりませんが、単にフィールドの「価値」を「ポンドやキログラム」という言葉に変更します。
しかし、 "1"と "2.2"の値が必要なHTMLページで他のJavaScript計算を行っているとします。そうであれば、PHPページの値を以下のように変更することができます。これは唯一の選択肢ではありませんが、十分に単純です。
if (ISSET($_POST['savecalories'])) {
session_start();
$currentweight = floatVal(mysqli_real_escape_string($db,$_POST['Weight']));
if (mysqli_real_escape_string($db,$_POST['WeightUnit']) == '1') $weightunit = 'Pounds'; else $weightunit = 'Kilograms';
//$weightunit = mysqli_real_escape_string($db,$_POST['WeightUnit']);
$activitytime = floatVal(mysqli_real_escape_string($db,$_POST['Time']));
if (mysqli_real_escape_string($db,$_POST['TimeUnit']) == '60') $timeunit = 'Minutes'; else $timeunit = 'Hours';
//$timeunit = mysqli_real_escape_string($db,$_POST['TimeUnit']);
$activity = mysqli_real_escape_string($db,$_POST['Activity']);
$calories = floatVal(mysqli_real_escape_string($db,$_POST['Calories']));
$userid = $_SESSION['userid'];
$query = mysqli_query($db,"INSERT INTO tracklog
(currentweight,weightunit,activitytime,timeunit,activity,calories,userid)
VALUES('".$currentweight."', '".$weightunit."', '".$activitytime."', '".$timeunit."','".$activity."', '".$calories."', '".$userid."')");
}
私はあなたの質問を正しく理解したと思います。
あなたの答えをありがとう!私はちょうどそれを試したが、今は何も私のSQLデータベースに保存されていません:/ – Mal1234
どのタイプのMySQLフィールドは、weightunitとtimeunitカラムですか? Varchar?整数?上記のコードが変更される前に少なくとも何かを挿入していましたか? – WeekendCoder
両方ともVarchar。ええ、両方の数値を挿入していました。しかし今、トークンのミスマッチがあると言っています。 – Mal1234