-2

I keep getting the following error for this function.

Parse error: syntax error, unexpected '$tempsql' (T_VARIABLE) in /home/vps20119/public_html/outlet/admin/internal/dcOrderFunctions.php on line 6

I don't get it. I can't find any syntax errors before I start defining / declaring the $tempsql. What am I over looking? Below is a copy of the entire file.

<?php
//A function to extract the QC from the Order number
function orderGetQC($dropcomOrderID){

            //Get the Product ID from the order.
            $tempsql = "SELECT * FROM `oc_order_product` WHERE `order_id` = '". $dropcomOrderID ."'";
            //runs the query (above) and puts the resulting data into a variable called $orderInfo.
            $orderInfo = $conn->query($tempsql);
            $temprow = $orderInfo->fetch_assoc();
            $productID = $temprow['product_id'];

            //Get the QC from the product ID.
            $tempsql2 = "SELECT * FROM `multi_quantity_received` WHERE `product_id` = '". $productID ."'";
            //runs the query (above) and puts the resulting data into a variable called $productInfo.
            $productInfo = $conn->query($tempsql2);
            $temprow2 = $productInfo->fetch_assoc();
            if( $productInfo->num_rows > 1){
                $QC = "multipleQCs";
            } else {
                $QC = $temprow2['qc'];
            }

            return $QC;

}
?>
8
  • 1
    there is no syntax error in the above code Commented Dec 10, 2016 at 1:47
  • 2
    their is no syntax error in your code, you sure you posted the right code?? Commented Dec 10, 2016 at 1:49
  • Try removing the comment before that line. It's a long shot but worth a try Commented Dec 10, 2016 at 1:49
  • 1
    @arif_suhail_123 +1 for considering that there actually might be another file that contains $tmpsql on line 6 :D Commented Dec 10, 2016 at 1:55
  • 2
    @Daidon With funky copy/paste and mixed charsets, I've seen stranger. Like I said, it's a long shot. But there's no syntax errors here Commented Dec 10, 2016 at 2:01

1 Answer 1

0

Good evening ID10T ERROR,

I had a similar issue not too long ago. The problem was, my FTP (FileZilla) started uploading my files in BINARY MODE instead of ASCII MODE. This causes the file being uploaded to get condensed. This causes a problem for code following single-line comments, such as the one presented in your code above.

Take this piece of code for example:

//Get the Product ID from the order.
$tempsql = "SELECT * FROM `oc_order_product` WHERE `order_id` = '". $dropcomOrderID ."'";

That is two simple, well-written lines of PHP! But what happens if the FTP condenses those lines into one? You get something like this:

//Get the Product ID from the order. $tempsql = "SELECT * FROM `oc_order_product` WHERE `order_id` = '". $dropcomOrderID ."'";

Notice, now the $tempsql variable is commented out, making it inaccessible (Or unexpected.) In your specific situation, it's being blocked by that first comment. If this is, indeed, your issue, there's two main things you can do to fix it. See below.

1. Turn single-line comments into block comments

Okay, this is really more of a work-around than a real fix, but if this works, you know that this is your issue! Simply turn all of your single-line comments into block comments like below.

<?php
/*A function to extract the QC from the Order number */
function orderGetQC($dropcomOrderID){

    /* Get the Product ID from the order. */
    $tempsql = "SELECT * FROM `oc_order_product` WHERE `order_id` = '". $dropcomOrderID ."'";
    /* runs the query (above) and puts the resulting data into a variable called $orderInfo. */
    $orderInfo = $conn->query($tempsql);
    $temprow = $orderInfo->fetch_assoc();
    $productID = $temprow['product_id'];

    /* Get the QC from the product ID. */
    $tempsql2 = "SELECT * FROM `multi_quantity_received` WHERE `product_id` = '". $productID ."'";
    /* runs the query (above) and puts the resulting data into a variable called $productInfo. */
    $productInfo = $conn->query($tempsql2);
    $temprow2 = $productInfo->fetch_assoc();
    if( $productInfo->num_rows > 1){
        $QC = "multipleQCs";
    } else {
        $QC = $temprow2['qc'];
    }

    return $QC;

}
?>

2. Change FileZilla (or related FTP) from Binary to ASCII mode.

1) Open FileZilla.

2) Open the settings menu by clicking 'Edit' on the toolbar, then clicking on 'settings'.

3) Under the 'Transfers' group, click on the option called 'File Types'.

4) Select the box that says 'ASCII'.

5) Press 'OK' and try to transfer the file again. Hopefully it should work!

I hope this was useful! If not, please leave a comment and we can try to figure something else out!

Regards,

Timothy

Sign up to request clarification or add additional context in comments.

4 Comments

if you are right you are magician
frankly i dont think random guessing is a good idea
@Dagon People who get a similar problem will at least see one solution that another person has already figured out. This answer (although it might not solve the OP's problem) is still a correct answer to the question that the OP posed in other cases. +1 from me
Good afternoon, do you believe this was an off-topic answer? I believed that it was definitely a plausible solution as OP's variable is not being recognized. My solution above shows that the code being condensed would cause the variable to be hidden, which in turn, would cause the error OP presented us with. Please correct me if I am wrong though, I don't want to be giving out false information. Thank for for the +1 Daidon!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.