Error with PHP parsing?
Posted by: mark (---.upc-i.chello.nl)
Date: October 27, 2006 10:46AM

Hello folks,

i have just installed the newsist version of WAMP.
and it is running good, but when i go to my test
site for a childeren week to get register, then
er is going something wrong.

the code is working on my old PHP configuration
on windows Server 2003.

I have now Windows XP with WAMP an i get the
code in my screen.

[dyny.org]

i see then above the site:

= 15){ ?>
Helaas, De aantal inschrijvingen zijn bereikt.

and that is wrong. here is a little bit of code:

<body>
<?PHP
// aantal inschrijvingen controleren zoanders blokkeren
$aantalinschrijvingen = mysql_query("SELECT COUNT(*) as aantal_records FROM kvw_database"winking smiley;

$maximaal = mysql_result($aantalinschrijvingen,0,'aantal_records');
if($maximaal >= 15){
?>
<p align="center" style="color:#FF0000; font-size: 16px;"><?php echo "Helaas, De aantal inschrijvingen zijn bereikt." ?>
<?PHP
exit;
}
?>


what do i wrong? can someone help me?



Post Edited (10-27-06 11:53)

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: mark (---.direct-adsl.nl)
Date: October 27, 2006 11:57AM

Hoi Folks!!

i have solved the problem!!!!

i have read somewhere that i have to use : <?PHP
to open PHP. i have use in my scripts sometimes
only : <? and that is not good. that is for ASP

when you use Apache and PHP you have to use allways

<?PHP to open and ?> to close :-)

best regards,

Mark

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: yfastud (---.cable.mindspring.com)
Date: October 27, 2006 11:19PM

Enable short_open_tag in php.ini in wamp/php

Hope this help

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: CyberSpatium (71.237.217.---)
Date: October 28, 2006 02:09AM

no, do not enable short tags in your php.ini file. if you are going to use xml you need to use full tags, plus that is standard php coding practice.

php manual at php.net says:

“Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.”

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: intosoul (---.vc.shawcable.net)
Date: October 28, 2006 05:48AM

I also have a php parsing error but not the same as Mark's situation.

My problem is with
"Parse error: parse error, unexpected $end "

Using the same file, when I upload to my web host provider, the same file works but not when I use wamp5 server. So I know it's not the file itself that is the problem. Any idea or help would be appreciated.

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: CyberSpatium (71.237.217.---)
Date: October 28, 2006 06:04AM

post some php code

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: intosoul (---.vc.shawcable.net)
Date: October 28, 2006 06:09AM

So here is the error msg"
"Parse error: parse error, unexpected $end in F:\Wamp\www\blog\wp-content\plugins\custom-smileys.php on line 518"

Below is the php code from the file (sorry I am not proficient in php coding so I don't know it is really the coding problem or not but the same file works at the web host server):
<?php
// Initialize
csm_init();

// Initialization function
function csm_init() {
global $wpdb;

// Add hooks
add_action("admin_menu", csm_add_pages); // Admin CP
add_filter("the_content", csm_convert); // Post content
add_filter("comment_text", csm_convert); // Comment

// Use docking box whenever u want
if ( get_option("csm_dbx"winking smiley == true ) {
add_action("dbx_post_sidebar", csm_add_box); // DBX box
if ( get_option("rich_editing"winking smiley == true ) {
update_option("rich_editing", false);
}
}

// Disable built-in smileys support, if needed
if ( get_option("use_smilies"winking smiley == 1 ) {
update_option("use_smilies", 0);
}

// Run the installer, if needed
if ( csm_first_run_detected() && !get_option("csm_remove"winking smiley ) {
csm_install();
} else if ( get_option("csm_remove"winking smiley == 1 ) {
update_option("csm_remove", 2);
} else {
delete_option("csm_remove"winking smiley;
}

}

// Detect first run
function csm_first_run_detected() {
global $wpdb, $table_prefix;
$tableExists = false;
$tables = $wpdb->get_results("show tables;"winking smiley;
foreach( $tables as $table ) {
foreach( $table as $value ) {
if( $value == "{$table_prefix}smileys" ) {
return false;
}
}
}
return true;
}

// Install Custom smileys
function csm_install() {
global $wpdb, $table_prefix;

$updated = false;

// Add some options
update_option('csm_path', 'yahoo'); // Path to smileys directory
update_option('csm_dbx', false); // Docking box
update_option('csm_ext', 'gif'); // Smileys' default extension
update_option('csm_spl', '5'); // Smileys per line

// Detect old version
$tableExists = false;
$tables = $wpdb->get_results("show tables;"winking smiley;
foreach( $tables as $table ) {
foreach( $table as $value ) {
if( $value == "qa_smileys" ) {
$wpdb->query("RENAME TABLE `qa_smileys` TO `{$table_prefix}smileys`"winking smiley;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` DROP `ID`"winking smiley;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` CHANGE `Name` `File` VARCHAR( 25 ) NOT NULL"winking smiley;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` ADD PRIMARY KEY ( `File` )"winking smiley;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` CHANGE `Value` `Emot` VARCHAR( 10 ) NOT NULL"winking smiley;
delete_option("qa_path"winking smiley;
delete_option("qa_extension"winking smiley;
delete_option("qa_spl"winking smiley;
$updated = true;
break;
}
}
}

if ( !$updated ) {
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$table_prefix}smileys` (`File` VARCHAR(25) NOT NULL, `Emot` VARCHAR(10) NOT NULL, PRIMARY KEY(`File`));"winking smiley;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo1', 'smiling smiley');"winking smiley;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo2', 'sad smiley');"winking smiley;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo3', 'winking smiley');"winking smiley;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo4', 'grinning smiley');"winking smiley;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo5', ';winking smiley');"winking smiley;
}
}

// Uninstall Custom Smileys, completely
function csm_uninstall() {
global $wpdb, $table_prefix;
$wpdb->query("DROP TABLE `{$table_prefix}smileys`"winking smiley;
delete_option("csm_path"winking smiley;
delete_option("csm_dbx"winking smiley;
delete_option("csm_ext"winking smiley;
delete_option("csm_spl"winking smiley;
echo '<div id="message" class="updated fade"><p>Table <b>dropped</b>. Please click <a href="../wp-admin/plugins.php?action=deactivate&plugin=custom-smileys.php">here</a> to deactivate Custom Smileys.</p></div>';
}

// Add Manage smileys and smileys Options page to Admin Panel
function csm_add_pages() {
add_management_page("Custom Smileys", "Custom Smileys", 8, __FILE__, "csm_management_page"winking smiley;
add_options_page("Custom Smileys", "Custom Smileys", 8, __FILE__, "csm_options_page"winking smiley;
}

// Convert emoticons to graphics on display - same as the default filter
function csm_convert($text) {
global $wpdb, $table_prefix;

// Get emoticons from DB, order by length
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY length(Emot) DESC"winking smiley;

// Find and Replace
foreach ( $result as $object ) {
$find[] = $object->Emot;
$replace[] = "<img src=\"" . get_option("siteurl"winking smiley . "/wp-includes/images/" . get_option("csm_path"winking smiley . "/" . $object->File . "." . get_option("csm_ext"winking smiley . "\" class=\"wp-smiley\" />";
}

$output = "";

// HTML loop taken from texturize function, could possible be consolidated
$textarr = preg_split("/(<.*>winking smiley/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
$stop = count($textarr); // loop stuff
for ( $i = 0; $i < $stop; $i++ ) {
$content = $textarr[$i];
if ( (strlen($content) > 0) && ('<' != $content{0}) ) { // If it's not a tag
$content = str_replace($find, $replace, $content);
}
$output .= $content;
}

return $output;
}

// Check if a file is an image or not
function csm_is_image($file, $extension = "gif"winking smiley {
return ( strpos($file, "." . $extension) !== false );
}

// Remove extension of a file
function csm_remove_ext($file) {
$ext = strrchr($file, "."winking smiley;
if($ext !== false) {
$file = substr($file, 0, -strlen($ext));
}
return $file;
}

// Smileys Manager
function csm_management_page() {
global $wpdb, $table_prefix;

// Check if emoticons are updated or not
if ( $_POST["Update"] ) {
$okay = true;

// Check if there are any duplicated fields or not
$count = array();
foreach ( $_POST as $field => $value ) {
if ( $count[$value] != "" && $value != ""winking smiley {
$okay = false;
}
$count[$value] = $field;
}

// If not, update the DB
if ( $okay ) {
foreach ( $_POST as $field => $value ) {
if ( $field != "Update" && trim($value) != "" ) {
$wpdb->query("REPLACE INTO `{$table_prefix}smileys` VALUES ('$field', '$value')"winking smiley;
}
}
echo '<div id="message" class="updated fade"><p><b>smileys updated.</b></p></div>';
} else {
echo '<div id="message" class="updated fade"><p><b>Duplicated emoticons detected.</b> Please correct them before continuing.</p></div>';
}
}
?>
<div class="wrap">
<h2>Custom Smileys Manager</h2>
<form method="POST">
<table>
<?php
// Initialize
$path = get_option("csm_path"winking smiley;
$handle = opendir("../wp-includes/images/" . $path);
$count = 0;

// Get emoticons from DB
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY `File`"winking smiley;
foreach ( $result as $object ) {
$emot[$object->File] = $object->Emot;
}

// Draw table
echo "<tr>";
while ( ($file = readdir($handle)) !== false ) {
if ( $file != "." && $file != ".." && csm_is_image($file, get_option("csm_ext"winking smiley) ) {
$count ++;
$smileys[] = $file;
if ( ($count % get_option("csm_spl"winking smiley == 1) && ($count > 1) ) {
echo "</tr><tr>";
}
$filename = csm_remove_ext($file);
$output = "<td align=\"center\"><img src=\"../wp-includes/images/$path/$file\" class=\"wp-smiley\" /></td>";
$output .= "<td><input type=\"text\" id=\"$filename\" name=\"$filename\" size=\"8\" maxlength=\"10\" value=\"$emot[$filename]\"/></td>";
echo $output;
}
}
?>
</table>
<p class="submit">
<input type="submit" name="Update" value="Update &raquo;" />
</p>
</form>
</div>
<?php
}

// Smileys Control Panel
function csm_options_page() {
// Check if preferences are updated or not
if ( $_POST["Update"] ) {
$updated = false;
if ( get_option("csm_path"winking smiley != $_POST["Path"] ) {
update_option("csm_path", $_POST["Path"]);
$updated = true;
}
if ( get_option("csm_dbx"winking smiley != $_POST["DBX"] ) {
update_option("csm_dbx", $_POST["DBX"]);
$updated = true;
}
if ( get_option("csm_ext"winking smiley != $_POST["Ext"] ) {
update_option("csm_ext", $_POST["Ext"]);
$updated = true;
}
if ( get_option("csm_spl"winking smiley != trim($_POST["SPL"]) ) {
if ( $_POST["SPL"] > 0 ) {
update_option("csm_spl", trim($_POST["SPL"]));
$updated = true;
}
}
if ( $updated ) {
echo '<div id="message" class="updated fade"><p><b>Preferences updated.</b> Click <a href="../wp-admin/edit.php?page=custom-smileys.php">here</a> if you want to go to Smileys Management page.</p></div>';
} else {
echo '<div id="message" class="updated fade"><p><b>No changes made.</b> Click <a href="../wp-admin/edit.php?page=custom-smileys.php">here</a> if you want to go to Smileys Management page.</p></div>';
}
}

// Check if user is about to uninstall Custom smileys or not
if ( $_POST["Uninstall"] ) {
update_option("csm_remove", 1);
csm_uninstall();
}
?>
<div class="wrap">
<h2>Preferences</h2>
<form method="POST">
<table class="optiontable">
<tr valign="top">
<th scope="row">
Smileys directory:
</th>
<td>
<select name="Path">
<?php
$selected = get_option("csm_path"winking smiley;
if ( $handle = opendir("../wp-includes/images"winking smiley ) {
while ( ($file = readdir($handle)) !== false ) {
if ( strpos($file, "."winking smiley === false ) {
if ( $selected == $file ) {
echo "<option name=\"$file\" selected=\"selected\" value=\"$file\">$file</option>";
} else {
echo "<option name=\"$file\" value=\"$file\">$file</option>";
}
}
}
}
?>
</select>
<br />
Smileys' directory (below <b>wp-includes/images</b>winking smiley
</td>
</tr>
<tr valign="top">
<th scope="row">
Default extension:
</th>
<td>
<select name="Ext">
<?php
$ext = array("gif", "jpg", "png"winking smiley;
$selected = get_option("csm_ext"winking smiley;
foreach ( $ext as $value) {
if ( $selected == $value ) {
echo "<option name=\"$value\" selected=\"selected\" value=\"$value\">$value</option>";
} else {
echo "<option name=\"$value\" value=\"$value\">$value</option>";
}
}
?>
</select>
<br />
Smileys' default extension
</td>
</tr>
<tr valign="top">
<th scope="row">
Smileys per line:
</th>
<td>
<input type="text" name="SPL" value="<?php echo get_option("csm_spl"winking smiley; ?>" />
<br />
Number of smileys displayed on each line in the management page (e.g. "5"winking smiley
</td>
</tr>
<tr valign="top">
<th scope="row">
Docking Box:
</th>
<td>
<?php
if ( get_option("csm_dbx"winking smiley == true ) {
?>
<input name="DBX" type="checkbox" id="DBX" value="true" checked="checked" />
<?php
} else {
?>
<input name="DBX" type="checkbox" id="DBX" value="true" />
<?php
}
?>
Add a docking box to Write page
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Update" value="Update Preferences &raquo;" />
</p>
</form>
</div>
<div class="wrap">
<h2>Usage</h2>
<form method="POST">
<table class="optiontable">
<tr valign="top">
<th scope="row">
Docking Box
</th>
<td>
In order to use Custom Smileys' docking box, you <b>must</b> uncheck the box that says "<b>Use the visual rich editor when writing</b>". This setting is located <a href="../wp-admin/profile.php">here</a>.
</td>
</tr>
<tr valign="top">
<th scope="row">
Comment Form
</th>
<td>
Clickable smileys can also be integrated into your Comment form by pasting the following code into your <b>comments.php</b> file, just before the comment form begins:<br />
<p><textarea cols="100%" rows="7">
<?php
$code = <<<HERE
<!-- Clickable smileys start here -->
<?php
if ( function_exists(csm_comment_form) ) {
csm_comment_form();
}
?>
<!-- Clickable smileys end here -->
HERE;
echo htmlspecialchars($code);
?>
</textarea></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
Smileys Formatting
</th>
<td>
Custom Smileys uses <b>wp-smiley</b> class to format your smileys. CSS example:
<p><textarea cols="100%" rows="6">
<?php
$code = <<<HERE
.wp-smiley {
border: 0pt none;
margin: 0px;
padding: 0px;
vertical-align: middle;
}
HERE;
echo htmlspecialchars($code);
?>
</textarea></p>
Just put these lines in your <b>style.css</b> file and you're all set.
</td>
</tr>
</table>
</form>
</div>
<div class="wrap">
<h2>Uninstallation</h2>
<form method="POST">
<table class="optiontable">
<tr valign="top">
<th scope="row">
<input type="submit" name="Uninstall" value="Uninstall Custom smileys" onclick="return confirm('Are you sure you wish to remove Custom Smileys completely?');" />
</th>
<td>
Click this button if you want to REMOVE Custom Smileys completely. Remember that this action CAN NOT be reversed.
</td>
</tr>
</table>
</form>
</div>
<?php
}

// Add clickable smileys to Comment form
function csm_comment_form() {
global $wpdb, $table_prefix;

// Get emoticons from DB & Display clickable smileys
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY `File`"winking smiley;
foreach ( $result as $object ) {
if ( file_exists("./wp-includes/images/" . get_option("csm_path"winking smiley . "/" . $object->File . "." . get_option("csm_ext"winking smiley) ) {
echo "<img src=\"" . get_option("siteurl"winking smiley . "/wp-includes/images/" . get_option("csm_path"winking smiley . "/" . $object->File . "." . get_option("csm_ext"winking smiley . "\" class=\"wp-smiley\" onclick=\"document.getElementById('comment').value += ' {$object->Emot}';\" />&nbsp;";
}
}
}

// Add docking box
function csm_add_box() {
global $wpdb, $table_prefix;
?>
<fieldset id="customsmileysbox" class="dbx-box">
<h3 class="dbx-handle">Custom Smileys</h3>
<div class="dbx-content">
<?php
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY `File`"winking smiley;
$count = 0;
foreach ( $result as $object ) {
if ( file_exists("../wp-includes/images/" . get_option("csm_path"winking smiley . "/" . $object->File . "." . get_option("csm_ext"winking smiley) ) {
$count ++;
if ( $count > 1 && $count % get_option("csm_spl"winking smiley == 1 ) {
echo "<br />";
}
echo "<img src=\"" . get_option("siteurl"winking smiley . "/wp-includes/images/" . get_option("csm_path"winking smiley . "/" . $object->File . "." . get_option("csm_ext"winking smiley . "\" class=\"wp-smiley\" onclick=\"document.getElementById('content').value += ' {$object->Emot}';\" />&nbsp;";
}
}
?>
</div>
</fieldset>
<?
}
?>

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: CyberSpatium (71.237.217.---)
Date: October 28, 2006 04:22PM

change:

// Add hooks
add_action("admin_menu", csm_add_pages); // Admin CP
add_filter("the_content", csm_convert); // Post content
add_filter("comment_text", csm_convert); // Comment

// Use docking box whenever u want
if ( get_option("csm_dbx"winking smiley == true ) {
add_action("dbx_post_sidebar", csm_add_box); // DBX box
if ( get_option("rich_editing"winking smiley == true ) {
update_option("rich_editing", false);
}

to:

// Add hooks
add_action("admin_menu", "csm_add_pages"winking smiley; // Admin CP
add_filter("the_content", "csm_convert"winking smiley; // Post content
add_filter("comment_text", "csm_convert"winking smiley; // Comment

// Use docking box whenever u want
if ( get_option("csm_dbx"winking smiley == true ) {
add_action("dbx_post_sidebar", "csm_add_box"winking smiley; // DBX box
if ( get_option("rich_editing"winking smiley == true ) {
update_option("rich_editing", false);
}

Options: ReplyQuote
Re: Error with PHP parsing?
Posted by: intosoul (---.vc.shawcable.net)
Date: October 29, 2006 04:44AM

Thanks CyberSpatium for taking the time to look up the codes and correcting them for me. It turned out after adding the open and closed quotes the script still had parse error message. Then, I saw the code error that Mark mentioned earlier. Turned out the script developer wrote sloopy codes. He was sometimes writing using short tags. Instead of <?PHP , he toward the end of the scripts, he got lazy with using only : <? . That was the cause of the parse error message. Thanks, the problem is solved.

Options: ReplyQuote


Sorry, only registered users may post in this forum.