Im facing one problem. I already created session. All I want is when someone clicks on submit button my php code executes. I want to store the name of user who clicked button into mysql. When I click on it I get an echo "created successful" but mysql table is filled with zeros. I can echo ".$r['username']."
and its ok.
<?php
session_start();
if($_SESSION['user']==''){
header("Location:login.php");
}else{
$dbh=new PDO('mysql:dbname=myDB;host=127.0.0.1', 'user', 'pass');
$sql=$dbh->prepare("SELECT * FROM users WHERE id=?");
$sql->execute(array($_SESSION['user']));
while($r=$sql->fetch()){
sql = "INSERT INTO table (tablerow) VALUES ('`".$r['username']."`')";
try {
$dbh->exec($sql);
echo " `".$r['username']."` inserted successfully";
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
}
$conn = null;
}
?>