简体   繁体   中英

What's wrong with my Syntax? (PHP/HTML)

Well, I've gone over this atleast 30 times, tried as many possible combinations that I could think of, can you spot the syntax error? (I can't, obviously). It doesn't display what it should be, instead it displays the actual html of the page!

The Code:

$ct->data[$key][1] =
  '<input id="quantity" name='."items[<?=$product_id;?>]".
  'type="text" value="'.$ct->data[$key][1].'" 
  style="background:#FFFFFF url(qty.png) no-repeat 4px 4px;

Can someone please tell me what I've done wrong? Any help/advice at all is appreciated.

Thanks!

Using short tags is a very bad practice. It makes code harder to read and it isn't enabled by default on most environments. Which can lead to mistakes like this one.

Always use the full <?php (and not <? ) and <?php echo "string" instead of <?="string"> . This will prevent many mistakes.

Then, it looks like you're trying to evaluate PHP in strings. echo "echo 'test'"; will never print test, it will always print echo 'test'. It's the same thing for items[<?=$product_id;?>] . First of all, it isn't even a valid PHP syntax and second of all, even if it was really, you can use $product_id without any other modification : items[$product_id] . ( edit : actually, I'm not even sure what you're trying to do here).

I'm not going to go over all your code, but it seems like you lack the basics of the language. It may be good to review them!

What is this?

name='."items[<?=$product_id;?>]".' type=

I think you meant

name="items[' . $product_id . ']" type=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM