我已經存儲了變量。我想將會話變量和其他通過表單填充的信息插入表中。我得到了它創建的消息,但沒有顯示在表格中。不能將會話變量存儲到數據庫中
我想獲取會話變量並將其存儲到「用戶名」 我試過$ username = $ r ['username'];但沒有工作。
<?php
session_start();
if($_SESSION['user']==''){
header("Location:login.php");
}else{
$dbh=new PDO('mysql:dbname=mydb;host=127.0.0.1', 'myusername', 'mypassword');
$sql=$dbh->prepare("SELECT * FROM users WHERE id=?");
$sql->execute(array($_SESSION['user']));
while($r=$sql->fetch()){
$username=$r['username']; <-im not sure if this is correct.
$ime=$_POST['ime'];
$priimek=$_POST['priimek'];
$email=$_POST['email'];
$izob=$_POST['izob'];
$izk=$_POST['izk'];
$prib=$_POST['prib'];
$opis=$_POST['opis'];
$sql = "INSERT INTO profil (ime, priimek, email, izob, izk, prib, opis) VALUES(`username`,`ime` , `priimek ` , `email` , `izob` , `izk` , `prib` , `opis`)";
try {
$dbh->exec($sql);
echo " created successfully";
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
}
$conn = null;
}
?>
CREATE TABLE profil(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(10),
ime VARCHAR(10) NOT NULL,
priimek VARCHAR(10) NOT NULL,
email VARCHAR(20),
izob VARCHAR(20),
izk VARCHAR(10),
prib VARCHAR(10),
opis VARCHAR(100),
);
感謝您的幫助
'的print_r($ R)',(在上面,你認爲這個問題是,並粘貼結果行) – FrankerZ