0
私はphpとPDO mysqlを使ってレコードを挿入しました。しかし成功の結果には影響しません。PDO - レコード挿入の問題?
何が問題ですか?
エラーテキストは次のとおりです。タグ発行を閉じる
DataBase Error: The user could not be added. SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 2failed
<?php //Post Params
$txt_studid ='RU010/08' ;//trim($_POST['txt_studid']);
$cost_year =1 ;//trim($_POST['status']);
$txt_tution = 700;//trim($_POST['txt_tution']);
$txt_food = 600;//trim($_POST['txt_food']);
$txt_accom = 500 ;//trim($_POST['txt_accom']);
?>
<?php //Query
$pdo = new PDO('mysql:host=localhost;dbname=erca_db', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$stmt = $pdo->prepare("INSERT INTO st_costshare(stud_id, template_id, Tuition_fee, food_fee, Accomod_fee)
VALUES(:studid, :cost_id, :tution, :food, :accomod");
$stmt->bindValue(":studid", $txt_studid);
$stmt->bindValue(":cost_id", $cost_year);
$stmt->bindValue(":tution", $txt_tution);
$stmt->bindValue(":food", $txt_food);
$stmt->bindValue(":accomod", $txt_accom);
$stmt->execute();
} catch (PDOException $e) {
echo "DataBase Error: The user could not be added.<br>".$e->getMessage();
} catch (Exception $e) {
echo "General Error: The user could not be added.<br>".$e->getMessage();
}
if ($stmt->rowCount()>0) {
echo "success";
} else {
echo "failed";
}
?>
テーブル構造を投稿できますか? – pes502