Home > OS >  Fatal error: Uncaught Error: Undefined constant "​" and array question
Fatal error: Uncaught Error: Undefined constant "​" and array question

Time:05-17

I'm trying to make a foreach function where a number in a table in phpmyadmin will increase each time value inside an array matches the "pet_id". And also this only execute whenever a submit button is pressed. This is my code in php file:

<?php
    if (isset($_POST['Submit'])) {
        if (isset($cart)) {
            // if product appeared
            foreach ($product->getData('cart') as $item):
                $cart = $product->getProduct($item['pet_id']);
                $subTotal[] = array_map(function ($item){
                    $sql = "UPDATE pet_info SET number_sold = number_sold   1 WHERE 
                    $item == pet_info.pet_id;";

                    $query1 = mysqli_query($con,$sql);
                    while ($pet_id = mysqli_fetch_array($query1)) {
                        execute($pet_id['pet_id']); 
                    }
                }); 
            endforeach;
        }   
    }​
?>

But I spent the last 2 hours searching for a solution but what i achieve is still errors:

Fatal error: Uncaught Error: Undefined constant "​" in C:\xampp\htdocs\testing\petsonthenet\partial\_checkout.php:121 Stack trace: #0 C:\xampp\htdocs\testing\petsonthenet\user_cart.php(7): include() #1 {main} thrown in C:\xampp\htdocs\testing\petsonthenet\partial\_checkout.php on line 121

Can someone help me please? I'd be very appreciated!!

This is the part of the code related to the cart

                <?php
                foreach ($product->getData('cart') as $item) :
                    $cart = $product->getProduct($item['pet_id']);
                    echo gettype($item);
                    $subTotal[] = array_map(function ($item){
            ?>
            <!-- cart item -->
            <div >
                <div >
                    <img src="<?php echo $item['image'] ?? "./images/pet (1).jpg" ?>" style="height: 150px; width:120px;" alt="cart1" >
                </div>
                
                <div >
                    <h5 ><?php echo $item['name'] ?? "Unknown"; ?></h5>
                    <h5 ><?php echo $item['pet_id'] ?? "Unknown"; ?></h5>
                    <small> <?php echo $item['breed'] ?? "Brand"; ?></small>
                        
                </div>

                <div >
                    <div >
                        $<span  data-id="<?php echo $item['pet_id'] ?? '0'; ?>"><?php echo $item['price'] ?? 0; ?></span>
                    </div>
                </div>
                <form method="post">
                            <input type="hidden" value="<?php echo $item['pet_id'] ?? 0; ?>" name="pet_id">
                            <button type="submit" name="delete-cart-submit" >Delete</button>
                </form>
            </div>
            <!-- !cart item -->
            <?php
                        return $item['price'];
                    }, $cart); // closing array_map function
                endforeach;
            ?>

CodePudding user response:

I just did a check on your error message, there was a unicode character that didn't display correctly in it, in quotes. So I determined this was a "typo", if I'm not mistaken you are using mac or linux, and open the Vietnamese typewriter.

You can paste the error message into your browser's javascript console. You will see the error character.

CodePudding user response:

You have a enter image description here

This appears to be an undefined constant to PHP.

Delete what is after that last curly brace.

CodePudding user response:

Have you check all $item value, make sure theres no empty value on it, and i think better use format print like sprintf.

<?php $sql = sprintf('UPDATE pet_info SET number_sold = number_sold   1 WHERE %d == pet_info.pet_id;',$item); ?>
  •  Tags:  
  • php
  • Related