Xtremer360 Posted January 16, 2011 Share Posted January 16, 2011 It keeps saying unexpected T_CONSTANT_ENCAPSED_STRING. What is a t_constant_encapsed string and why am I getting there error? if ( isset( $_POST['menuid'] ) ) { $menuid = (int)$_POST['menuid']; $query = "SELECT COUNT(`sortorder`) AS numOrder FROM `menuitems` WHERE `menu_id` = '".$menuid."'"; $result = mysqli_query ($dbc, $query); $row = mysqli_fetch_array( $result, MYSQL_ASSOC ); $sortorder = $row[ 'numOrder' ] + 1; echo $sortorder; } Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/ Share on other sites More sharing options...
jcbones Posted January 16, 2011 Share Posted January 16, 2011 Post the complete error, and the complete script (or at least 5 lines before, and after the error). Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160082 Share on other sites More sharing options...
Xtremer360 Posted January 16, 2011 Author Share Posted January 16, 2011 Well its saying its coming from this page maybe I'm missing something. <?php // Include the database page require ('../inc/dbconfig.php'); if ( isset( $_POST['menuid'] ) ) { $menuid = (int)$_POST['menuid']; $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '".$menuid"'"; $result = mysqli_query ($dbc, $query); $row = mysqli_fetch_array( $result, MYSQL_ASSOC ); $order = $row[ 'numOrder' ] + 1; echo $order; } if (isset($_POST['submitmenuitem'])) { $menuid = mysqli_real_escape_string($dbc, $_POST['menuid']); $itemname = mysqli_real_escape_string($dbc, $_POST['itemname']); $itemurl = mysqli_real_escape_string($dbc, $_POST['itemurl']); $sortorder = mysqli_real_escape_string($dbc, $_POST['sortorder']); $contentpage = mysqli_real_escape_string($dbc, $_POST['contentpage']); $newscategory = mysqli_real_escape_string($dbc, $_POST['newscategory']); $application = mysqli_real_escape_string($dbc, $_POST['application']); $query = "SELECT * FROM `menus` WHERE (`itemname` = '".$itemname"') OR (`itemurl` = '".$itemurl."') OR (`contentpage_id` = '".$contentpage."') OR (`application_id` = '".$application."') OR (`newscategory_id` = '".$newscategory."')"; $result = mysqli_query ( $dbc, $query ); // Run The Query $rows = mysqli_num_rows($result); echo $query; if ($rows == 0) { $query = "INSERT INTO `menuitems` (menu_id, itemname, itemurl, sortorder, contentpage_id, newscategory_id, application_id, creator_id, datecreated, enabled) VALUES ('".$menuid."','".$itemname."','".$itemurl."','".$sortorder."','".$contentpage."', '".$newscategory."', '".$application."', 1, NOW(), 0)"; mysqli_query($dbc, $query) ; echo "good"; } else { $row = mysqli_fetch_array($result); if (($row['itemname'] == $itemname) && ($row['itemurl'] == $itemurl) && ($row['contentpage_id'] == $contentpage) && ($row['application_id'] == $application) && ($row['newscategory_id'] == $newcategory)) echo 'bad6'; elseif ($row['newscategory_id'] == $newscategory) echo 'bad5'; elseif ($row['application_id'] == $application) echo 'bad4'; elseif ($row['contentpage_id'] == $contentpage) echo 'bad3'; elseif ($row['itemurl'] == $itemurl) echo 'bad2'; elseif ($row['itemname'] == $itemname) echo 'bad1'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160085 Share on other sites More sharing options...
revraz Posted January 16, 2011 Share Posted January 16, 2011 Post the exact error with the line number Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160093 Share on other sites More sharing options...
Xtremer360 Posted January 16, 2011 Author Share Posted January 16, 2011 <b>Parse error</b>: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in <b>/home/content/y/a/n/yankeefaninkc/html/efedmanager/processes/menuitem.php</b> on line <b>8</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160097 Share on other sites More sharing options...
kenrbnsn Posted January 16, 2011 Share Posted January 16, 2011 In this line <?php $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '".$menuid"'"; ?> you forgot the "." between $menuid & the "'". It should be <?php $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '".$menuid . "'"; ?> This line can be written <?php $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '$menuid'"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160099 Share on other sites More sharing options...
Pikachu2000 Posted January 16, 2011 Share Posted January 16, 2011 There's really no need for all the concatenation when using double-quoted strings. It just leads to errors like this. $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '$menuid'"; Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160101 Share on other sites More sharing options...
Xtremer360 Posted January 16, 2011 Author Share Posted January 16, 2011 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/#findComment-1160105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.