Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.