如何在成功创建的表的会话消息中回显变量

时间:2017-06-01 06:40:44

标签: php session session-variables

我有一个php页面,脚本正在搜索是否存在特定名称的表。如果不存在表,则显示合适的消息。如果表存在,它会向其添加一些数据并显示成功会话消息。现在,我想将会话消息显示为Data added to ABC (name of the chosen table) successfully。相反,我收到的会话消息为Data added to $table sucessfully

请帮忙。以下是我的代码 -

<?php 
require_once("config.php");
require_once("config2.php");
$keyQ = $db->query("SELECT * FROM Collection where id = 
$Id"); 
$kVal = $kewyQ->fetch(PDO::FETCH_ASSOC);
$table = trim($kVal['words']);
try
{   
// Select 1 from table_name will return false if the table does not exist.
$value = $db2->query("select 1 from `$table` LIMIT 1");
}catch (PDOException $e) {
echo "$table does not exist";
exit;
}
if($value !== FALSE)
{
........
........
session_start();
$_SESSION['success'] = 'Data added to $table successfully.';
header('location:list2.php');
}
?>

1 个答案:

答案 0 :(得分:2)

使用Double&#34;&#34;引号而不是单引号在字符串中呈现变量。

"Data added to $table successfully.";