Jump to content

unexpected T_CONSTANT_ENCAPSED_STRING


Xtremer360

Recommended Posts

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;
}

Link to comment
https://forums.phpfreaks.com/topic/224577-unexpected-t_constant_encapsed_string/
Share on other sites

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';    
        
    }
    
}
        
?>

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 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.