我编写了以下代码,但它提供了解析错误。 这是我的代码。
<?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的数组,我用它将字段值放在数据库中, 但解析错误发生如下:
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING .
我尝试了很多组合,但同样的问题也出现了。
答案 0 :(得分:5)
在SQL查询中,将'$out[]'
的所有条目替换为{$out[]}
并尝试使用IDE:NetBeans或PhpStorm。
另外,不要忘记sanitize your data in SQL,请考虑使用PDO,不要使用结束?>
标记。
您的固定代码:
<?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";