dongshenyu4638 2013-11-16 23:56
浏览 26
已采纳

点击链接不会将我带到目标页面。 来自Murach PHP书籍

Hi I'm very new to php and I'm going over the Murach PHP book. I'm having a problem with clicking on a link in the categories section because when it clicks on the link it ads ?category_id=3 but the problem is it adds it after add_product.php like-> http://localhost/my_murach_php/add_product.php?category_id=3

I want it to add after http://localhost/my_murach_php/ so it looks like http://localhost/my_murach_php/?category_id=3

I am able to see the categories when i click on the links before I do anything with adding products. I could see the category info on the index page and when I click on it from the index page I get to go to http://localhost/my_murach_php/add_product_form.php (good) to add a product I click on the button and it takes me to http://localhost/my_murach_php/add_product.php(good) then when I click a category I get this page http://localhost/my_murach_php/add_product.php?category_id=1 (not good) I would like it to be this page http://localhost/my_murach_php/?category_id=3

Here's how I Included the link on the index page

        <li>
            <a href="?category_id=<?php echo $category['categoryID']; ?>">
                <?php echo $category['categoryName']; ?>
            </a>
        </li>

I have include("index.php"); in the add_product.php file

I guess the problem is going back to the root directory when I am on the http://localhost/my_murach_php/add_product.php?category_id=1 page.

Thank you

  • 写回答

1条回答 默认 最新

  • dongyan8929 2013-11-17 00:01
    关注

    if you use a href like "?category_id=..." then the browser assumes you just want to add this to your CURRENT url. So to go to the url you want, just use the full url you need, like:

    <a href="http://localhost/my_mutach_php?category_id=<?php echo $category['categoryID']; ?>">
    

    Btw. <?php echo can be written as <?= to make it simpler and more readable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法