我有一個多頁面的調查表單,我已經在PHP和MySQL中構建。每個頁面要求用戶在調查結束時選擇1到10之間的數字,以便將數據插入到MySQl數據庫中。添加多個字段的值,然後插入到MySQl列php
我需要做的是創建一個額外的列,將所有2個字段的值相加並將其插入到total_score字段中。
我有點卡住了,如果能指向我會在正確的方向,這將是可怕的。
我的代碼如下:
<?php
session_start(); // Session starts here.
$servername = "";
$username = "";
$password = "";
$dbname = "";
$_SESSION['answer_20'] = $_POST['answer_20'];
$firstname = $_SESSION['firstname'] ;
$lastname = $_SESSION['lastname'];
$gender = $_SESSION['gender'];
$postcode = $_SESSION['postcode'];
$ethnicity = $_SESSION['ethnicity'] ;
$lbote = $_SESSION['lbote'];
$atsi = $_SESSION['atsi'];
$numberofchildreninncare = $_SESSION['numberofchildreninncare'] ;
$youngestchild = $_SESSION['youngestchild'];
$ifother = $_SESSION['ifother'];
$eldestchild = $_SESSION['eldestchild'];
$ageofchild = $_SESSION['ageofchild'];
$relationship = $_SESSION['relationship'];
$education = $_SESSION['education'];
$liveshome = $_SESSION['liveshome'];
$answer_01 = $_SESSION['answer_01'];
$answer_02 = $_SESSION['answer_02'];
$answer_03 = $_SESSION['answer_03'];
$answer_04 = $_SESSION['answer_04'];
$answer_05 = $_SESSION['answer_05'];
$answer_06 = $_SESSION['answer_06'];
$answer_07 = $_SESSION['answer_07'];
$answer_08 = $_SESSION['answer_08'];
$answer_09 = $_SESSION['answer_09'];
$answer_10 = $_SESSION['answer_10'];
$answer_11 = $_SESSION['answer_11'];
$answer_12 = $_SESSION['answer_12'];
$answer_13 = $_SESSION['answer_13'];
$answer_14 = $_SESSION['answer_14'];
$answer_15 = $_SESSION['answer_15'];
$answer_16 = $_SESSION['answer_16'];
$answer_17 = $_SESSION['answer_17'];
$answer_18 = $_SESSION['answer_18'];
$answer_19 = $_SESSION['answer_19'];
$answer_20 = $_SESSION['answer_20'];
$client_id = $_SESSION['client_id'];
$family_id = $_SESSION['family_id'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO results (firstname,lastname,gender,postcode,ethnicity,lbote,atsi,numberofchildreninncare,youngestchild,ageofchild,ifother,eldestchild,relationship,education,liveshome,answer_01,answer_02,answer_03,answer_04,answer_05,answer_06,answer_07,answer_08,answer_09,answer_10,answer_11,answer_12,answer_13,answer_14,answer_15,answer_16,answer_17,answer_18,answer_19,answer_20,client_id,family_id,parent_subscale,connect_subscale,total_score)
VALUES ('$firstname','$lastname','$gender','$postcode','$ethnicity','$lbote','$atsi','$numberofchildreninncare','$youngestchild','$ageofchild','$ifother','$eldestchild','$relationship','$education','$liveshome','$answer_01','$answer_02','$answer_03','$answer_04','$answer_05','$answer_06','$answer_07','$answer_08','$answer_09','$answer_10','$answer_11','$answer_12','$answer_13','$answer_14','$answer_15','$answer_16','$answer_17','$answer_18','$answer_19','$answer_20','$client_id','$family_id','$parent_subscale','$connect_subscale','$total_score')";
$today = date("d M Y");
if ($conn->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
哪一個(變量名?)? – JYoThI
你好,基本上我想加上answer_01的數字/值到answer_20然後插入int到total_score列 – Phil
試試我更新的答案@Phil – JYoThI