简体   繁体   English

我的语法有什么问题? (PHP / HTML)

[英]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? 好吧,我至少检查了30次,尝试了我能想到的尽可能多的组合,您能发现语法错误吗? (I can't, obviously). (显然不能)。 It doesn't display what it should be, instead it displays the actual html of the page! 它不显示应有的内容,而是显示页面的实际html!

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"> . 始终使用完整的<?php (而不是<? )和<?php echo "string"而不是<?="string"> This will prevent many mistakes. 这样可以防止很多错误。

Then, it looks like you're trying to evaluate PHP in strings. 然后,看起来您正在尝试以字符串形式评估PHP。 echo "echo 'test'"; will never print test, it will always print echo 'test'. 永远不会打印测试,它将始终打印echo'test'。 It's the same thing for items[<?=$product_id;?>] . 对于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] . 首先,它甚至不是有效的PHP语法,其次,即使确实如此,您也可以使用$ product_id而不进行任何其他修改: 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=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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