Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试在sql查询中进行一些回显_Php_Mysql_Sql - Fatal编程技术网

Php 尝试在sql查询中进行一些回显

Php 尝试在sql查询中进行一些回显,php,mysql,sql,Php,Mysql,Sql,我需要在SQL查询中回显一些内容 我注意到这不起作用: $usernames = echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); $file = $_GET['file']; $sql="INSERT INTO bekeken(username, filename)VALUES(".$usernames.", '".$fileloc."')"; $result=mysql_query($sql)

我需要在SQL查询中回显一些内容

我注意到这不起作用:

$usernames = echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');  
$file = $_GET['file'];


$sql="INSERT INTO bekeken(username, filename)VALUES(".$usernames.", '".$fileloc."')";
$result=mysql_query($sql);
echo thingy工作得很完美,它会以应有的方式响应用户名

但是现在我想在数据库中插入这个用户名和一个通过PHP GET接收的文件名

我想我做错了很多,但我看不出来

提前谢谢

标记

完整代码:

  mysql_connect("localhost", "movidz", "password!") or die(mysql_error());
  mysql_select_db("movidz") or die(mysql_error());

  $file = $_GET['file'];

  $sql_scale = "SELECT * FROM films WHERE filename = '".$file."'";
  $result_scale = mysql_query($sql_scale)or die(mysql_error());

  while($row = mysql_fetch_array($result_scale)){$titel=$row['titel'];}
  echo "<div class='player_filmtitel_div'><h1 class='player_filmtitel'>".$titel."</h1></div>";
您正在插入$fileloc,但正在定义$file


实际上,您正在设置一个等于echo htmlentities的变量。。。。没有必要回显它,因为htmlentities已经返回了一个字符串。如果需要的话,您可以在以后回显它。echo仅用于显示在纯html中的回显内容。因此,您的代码应该如下所示:

$usernames = htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');  
$file = $_GET['file'];


$sql="INSERT INTO bekeken(username, filename) VALUES('{$usernames}', '{$file}')";
$result=mysqli_query($connection, $sql);

除了使用未定义的$fileloc之外,您的报价还有很大差距。另外,我建议使用mysqli\uup>所有这些代码都包含在php标记中吗?您连接到数据库了吗?在编写INSERT语句之前?是的,它包含在PHP标记中:是的,在相同的PHP标记之间有一个MySQL连接。我编辑了主要帖子。嗨,我根本不需要回显它,这只是一个测试。我只需要它将用户名写入数据库,而且我只知道htmlentities$_SESSION['user']['username'],ENT_引号,'UTF-8';有效。@user3915031我的其余答案应该仍然相关。你的代码有很多错误,应该会有所帮助。
$usernames = htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');  
$file = $_GET['file'];


$sql="INSERT INTO bekeken(username, filename) VALUES('{$usernames}', '{$file}')";
$result=mysqli_query($connection, $sql);