Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
911 views
in Technique[技术] by (71.8m points)

mysql - PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or 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";
?>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

Your fixed code:

<?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";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...