I have this error :Parse error: syntax error, unexpected '$db_field' (T_VARIABLE) in C:\Program Files (x86)\EasyPHP-12.1\www\penet.hi2.ro\cheats.php on line 110

And the code is :

<?PHP
                require ("connect.php");
                //$db_handle = mysql_connect($server, $user_name, $password); =>$connect
                $db_found = mysql_select_db($_mysql_db, $connect);

                if ($db_found) {

                $SQL = "SELECT * FROM cheats";
                $result = mysql_query($SQL);

                while ($db_field = mysql_fetch_assoc($result)) 
                {
                    //print ("<li>");
                    //print ("<a href="$db_field['Image'] . " class="pirobox" title="$db_field['Titlu'] . ">");
                    //print ("<img src="$db_field['Image'] . " alt="" /></a>");
                    //print ("<p>$db_field['Content'] . </p>");
                    //print ("<div class="button"><pre><a href="nextgen.php">Read more</a><a href="$db_field['Download'] . ">Download</a></pre></div>");
                    //print ("</li>");
                    $mesaj="<li><a href="$db_field['Image']" class="pirobox" title="$db_field['Titlu']"><img src="$db_field['Image']"/></a><p>$db_field['Content']</p><div class="button"><pre><a href="index.php">Read More</a><a href="$db_field['Download']">Download</a></pre></div></li>";
                    print ("$mesaj");

                    //print $db_field['Titlu'] . "<BR>";
                    //print $db_field['Content'] . "<BR>";
                    //print $db_field['Image'] . "<BR>";
                    //print $db_field['Download'] . "<BR>";
                }

                mysql_close($connect);

                }
                else {
                print "Database NOT Found ";
                mysql_close($connect);
                }

            ?>

Line 110 is $mesaj="..."

Recommended Answers

All 3 Replies

Firstly: you are mixing double quotes for PHP strings with double quotes for html attributes. Escape the later.
Secondly: composite variables in a string should be enclosed in curly braces to get parsed correctly.

$mesaj="<li><a href=\"{$db_field['Image']}\" class=\"pirobox\" title=\"{$db_field['Titlu']}\"><img src=\"{$db_field['Image']}\"/></a><p>{$db_field['Content']}</p><div class=\"button\"><pre><a href=\"index.php\">Read More</a><a href=\"{$db_field['Download']}\">Download</a></pre></div></li>";

Thanks a lot!

You are welcome. If no more questions please mark this as solved. Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.