简体   繁体   English

为什么

[英]Why <a href="..." is not working?

I am new to PHP.我是 PHP 新手。 Trying to pass variable through href, but not working properly.Can someone please help TIA, here is my code:试图通过 href 传递变量,但无法正常工作。有人可以帮助 TIA,这是我的代码:

while($rows=mysql_fetch_array($result)){
echo "<tr><td>".$rows{'bi_SKU'}.
      "<td>".$rows{'bi_title'}.
      "<td>".$rows{'bi_author'}. 
      "</td>"
        "<td><a href=CopyAdd.php?SKU=".$rows{'bi_SKU'}.

您需要用引号包裹href值 -

<a href='CopyAdd.php?SKU=".$rows{'bi_SKU'}."'

Modify your code...修改你的代码...

while($rows=mysql_fetch_array($result)){
echo "<tr><td>".$rows{'bi_SKU'}.
      "<td>".$rows{'bi_title'}.
      "<td>".$rows{'bi_author'}. 
      "</td>"
        "<td><a href='CopyAdd.php?SKU=".$rows{'bi_SKU'}."'

Note: Quotes is missing....注意:引号丢失....

Modify:调整:

while($rows=mysql_fetch_array($result)){
echo "<tr><td>".$rows{'bi_SKU'}.
  "<td>".$rows{'bi_title'}.
  "<td>".$rows{'bi_author'}. 
  "</td>".
    "<td><a href='CopyAdd.php?SKU=".$rows{'bi_SKU'}."'>...</a>".

you missing quotes.你缺少引号。 Try it尝试一下

<a href='CopyAdd.php?SKU=".$rows{'bi_SKU'}."'

Try This..尝试这个..

while($rows=mysql_fetch_array($result)){
   echo "<tr>
           <td>".$rows{'bi_SKU'}."</td>
           <td>".$rows{'bi_title'}."</td>
           <td>".$rows{'bi_author'}."</td>
           <td><a href='CopyAdd.php?SKU=".$rows{'bi_SKU'}."'>...</a></td>
        </tr>";
}

td & tr tags closed, anchor tag closed and quotes added to href . td & tr标签关闭, anchor标签关闭,引号添加到href When you indent the code properly most of the syntax errors can be spotted easily.当您正确缩进代码时,可以轻松发现大多数语法错误。 Also use a good IDE to do that for you.也可以使用一个好的 IDE 来为你做这件事。

I don't think the single quote is not the problem.我不认为单引号不是问题。
The problem is that he missed the closing anchor tag.问题是他错过了结束锚标签。
href should work without single quotes also . href应该在没有单引号的情况下工作
Solution is you need to close the anchor tag first .解决方案是您需要先关闭锚标记。

"<td><a href=CopyAdd.php?SKU=".$rows{'bi_SKU'}.">...</a>".
  1. You are not closing your <td> .您没有关闭<td>
  2. Link is not closed: <a></a>链接未关闭: <a></a>
  3. Missing link text: <a>CLICK</a>缺少链接文本: <a>CLICK</a>
  4. Your href is missing ' around value: <a href='#'>CLICK</a>您的href缺少'值: <a href='#'>CLICK</a>
  5. Array elements are accessed via [] but not via {} (turn on error reporting to see errors).数组元素通过[]而不是通过{} (打开错误报告以查看错误)。
  6. You are using mysql_ that is deprecated.您正在使用已弃用的mysql_ Use PDO or mysqli_使用PDOmysqli_

You can use " and surround variable with {} to put it safely in string.您可以使用"并用{}包围变量以将其安全地放入字符串中。

while($rows = mysql_fetch_array($result)) {
    echo "<tr>
         <td>{$rows['bi_SKU']</td>
         <td>{$rows['bi_title']}</td>
         <td>{$rows['bi_author']}</td>
         <td>
             <a href='CopyAdd.php?SKU={$rows{'bi_SKU'}'>SKU</a>
         </td>
   </tr>";
}

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

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