PHP 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,期待 T_STRING 或 T_VARIABLE 或 T_NUM_STRING [英] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

查看:28
本文介绍了PHP 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,期待 T_STRING 或 T_VARIABLE 或 T_NUM_STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了以下代码,但它给出了解析错误.这是我的代码.

i have written the following code but it is giving parse error . here is my code.

<?php

$link = mysql_connect('localhost', 'root', '9829126849');

if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_select_db("recruitmentdb", $link); 

$sql="
    INSERT INTO 
        recruitmentapp_candidate
            (
                id,
                name,
                contact1,
                contact2,
                contact3,
                e_mail,
                reference_type,
                resume_urce,
                date_of_first_contact,
                hr_contact,
                experience_level,
                current_employer,
                current_city,
                highest_degree,
                year_of_highest_degree,
                prominent_college,
                possible_projects,
                skill_set,
                track,
                status,
                offer_date,
                acceptance_date,
                joining_date,
                joining_date,
                comment,
                feedback_temp,
                upload_date,
                vacancy_id
            )
    VALUES 
            (
                null,
                '$out['Name']',
                null, 
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                '$out['ExpLevel']',
                '$out['CurrEmp']',
                '$out['CurrCity']',                     
                '$out['HighestDegree']',
                '$out['Year_Passing']',
                null,
                null,
                '$out['Skill_set']',
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
            )
";

if (!mysql_query($sql,$link))
{
    die('Error: ' . mysql_error());
}
echo "1 record added";
?>

我有一个名为 $out 的数组,我使用它来将提交的值放入数据库中,但是出现如下解析错误:

I have an array named $out and I am using it to place the filed values in the database, but parse error occurs as follows:

PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING .

我尝试了很多组合,但出现同样的问题.

i have tried many combinations but same problem occurs.

推荐答案

在 SQL 查询中,将 '$out[]' 的所有条目替换为 {$out[]}代码>
并尝试使用 IDE:NetBeans 或 PhpStorm.

In SQL-query replace all entries of '$out[]' by {$out[]}
And try to use IDE: NetBeans or PhpStorm.

另外,不要忘记清理 SQL 中的数据,考虑使用 PDO,不要使用关闭 ?> 标记.

Also, don't forget to sanitize your data in SQL, consider to use PDO and don't use closing ?> tag.

您的固定代码:

<?php

$link = mysql_connect('localhost', 'name', 'password');
if (!$link)
{
    die('Could not connect: '.mysql_error());
}
echo 'Connected successfully';
mysql_select_db("recruitmentdb", $link);

$sql = "INSERT INTO recruitmentapp_candidate(id,name,contact1,contact2,contact3,e_mail,reference_type,resume_urce,date_of_first_contact,hr_contact,experience_level,current_employer,current_city ,highest_degree,year_of_highest_degree,prominent_college ,possible_projects,skill_set,track ,status ,offer_date,acceptance_date,joining_date,joining_date,comment,feedback_temp,upload_date,vacancy_id)VALUES (null,{$out['Name']},null, null,null,null,null,null,null, null,{$out['ExpLevel']},{$out['CurrEmp']},{$out['CurrCity']}, {$out['HighestDegree']},{$out['Year_Passing']},null,null,{$out['Skill_set']},null,null,null,null,null,null,null,null,null,null)";
if (!mysql_query($sql, $link))
{
    die('Error: '.mysql_error());
}
echo "1 record added";

这篇关于PHP 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,期待 T_STRING 或 T_VARIABLE 或 T_NUM_STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆