Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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 试图将数据插入mysql时,T_封装了_和_空格错误_Php_Mysql_Parsing_Insert - Fatal编程技术网

Php 试图将数据插入mysql时,T_封装了_和_空格错误

Php 试图将数据插入mysql时,T_封装了_和_空格错误,php,mysql,parsing,insert,Php,Mysql,Parsing,Insert,我一直在尝试使用php将数据插入mysql,但遇到了以下错误解析错误:语法错误、意外的T_-ENCAPSED_和_-WHITESPACE 这是我的插入文件 <?php include_once 'include.php'; include_once 'header.php'; //$dbhandle = mysql_connect($hostname, $DBUser, $DBPasswd) // or die("Unable to connect to

我一直在尝试使用php将数据插入mysql,但遇到了以下错误解析错误:语法错误、意外的T_-ENCAPSED_和_-WHITESPACE

这是我的插入文件

<?php
    include_once 'include.php';
    include_once 'header.php';

    //$dbhandle = mysql_connect($hostname, $DBUser, $DBPasswd) 
    // or die("Unable to connect to MySQL");
    //echo "Connected to MySQL<br>";

    $DBsubmit="INSERT INTO User (fname, lname, email, password, institution, expertise)   
               VALUES('$_POST['fname']', '$_POST['lname']', '$_POST['email']', '$_POST['password']', '$_POST['institution']', '$_POST['expertise']')";
    $result=mysql_query($DBsubmit)

    //echo "1 record added";

    // close connection 
    mysql_close();
?>

字符串内部的数组访问语法与外部不同。更改为:

{$_POST['fname']}

查询
行中还缺少分号


您的代码也尽可能容易受到攻击。您应该对PDO或mysqli使用正确的参数化查询。

您的查询在SQL注入中非常容易受到攻击。我建议改用
mysql\u real\u escape\u string

$DBsubmit=sprintf("INSERT INTO User (fname, lname, email, `password`, institution, expertise)
VALUES('%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($_POST['fname']),
mysql_real_escape_string($_POST['lname']),
mysql_real_escape_string($_POST['email']),
mysql_real_escape_string($_POST['password']),
mysql_real_escape_string($_POST['institution']),
mysql_real_escape_string($_POST['expertise']));

您在这里还忘记了分号
$result=mysql\u查询($DBsubmit)
->
$result=mysql\u查询($DBsubmit)不要存储纯文本密码,转义传入的数据或至少转义它们,不要使用旧的mysql_uu函数。。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果你选择PDO,我更喜欢你的答案。
$DBsubmit=sprintf("INSERT INTO User (fname, lname, email, `password`, institution, expertise)
VALUES('%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($_POST['fname']),
mysql_real_escape_string($_POST['lname']),
mysql_real_escape_string($_POST['email']),
mysql_real_escape_string($_POST['password']),
mysql_real_escape_string($_POST['institution']),
mysql_real_escape_string($_POST['expertise']));