简体   繁体   English

如何从 html 中的一个按钮获取两个值?

[英]How do I get two values from one button in html?

this line is what Im using to send the values:这一行是我用来发送值的:

<a class="btn btn-danger"href="remove_profesor.php? prof_id=<php echo $row['prof_id'];?> course_section=<php echo $row['course_section'] ;?>

Im trying to have button remove the assigned professor to the class.我试图让按钮删除分配给 class 的教授。 On the "view_courses.php" page theres a table with all the courses and theres a button next to each course that allows you to remove the professor that is assigned to that course.在“view_courses.php”页面上,有一个包含所有课程的表格,每门课程旁边都有一个按钮,可让您删除分配给该课程的教授。 The button references "remove_professor.php".该按钮引用“remove_professor.php”。 The issue im having is that "remove_professor.php" isnt recieving the second value which is "course_section".我遇到的问题是“remove_professor.php”没有收到第二个值,即“course_section”。

This line is what im using to receive the values:这条线是我用来接收值的:

 $prof_id = $_GET['prof_id'];
 $course_section = $_GET['course_section'];

When I check the browser the values seems to be sending but then it gives me an error on the $course_section line, it says Undefined array key "course_section"当我检查浏览器时,这些值似乎正在发送,但它在 $course_section 行上给了我一个错误,它显示未定义数组键“course_section”

I think this code will help you
<?php 
    $prof_id = $row['prof_id'];                // this value is coming from database as passing to variable 
    $course_section= $row['course_section'];   // this value is coming from database as passing to variable 
?>
       
        <a class="btn btn-danger" href="remove_profesor.php?prof_id=<?php echo $prof_id?> &course_section=<?php echo $course_section?>">Click Here </a>

There is MULTIPLE issues with your a tag.. This is the correction(s) -- I'll explain below..a标签存在多个问题.. 这是更正- 我将在下面解释..

<a class="btn btn-danger" href="remove_profesor.php?prof_id=<?php echo $row['prof_id'];?>&course_section=<?php echo $row['course_section'] ;?>">LINK</a>
  1. your php tags were invalid -- They need to be <?php not <php ..您的php标签无效——它们必须是<?php而不是<php ..

  2. Your <a> tag was incomplete.. No end quote and no end carat..您的<a>标签不完整.. 没有结束引号,也没有结束克拉..

  3. You need to something to LINK.. And have and end tag </a>你需要一些东西来链接..并且有和结束标签</a>

  4. You had a space in the URL parameters.. No spaces..您在 URL 参数中有一个空格..没有空格..

  5. Separate parameters with an ampersand &&分隔参数

To send multiple parameters with a GET, you have to separate them with & , like this:要使用 GET 发送多个参数,您必须用&分隔它们,如下所示:

<a class="btn btn-danger" href="remove_profesor.php?prof_id=<?php echo $row['prof_id'];?>&course_section=<?php echo $row['course_section'];?">(link)</a>

It also seems that you write <php instead of the correct <?php .您似乎也写了<php而不是正确的<?php

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

相关问题 如何从一个选择选项中获取两个值? - how can i get two values from one select option? 如何使两个数据库显示在两个单选按钮上,每个按钮选择一个 - How do I get two databases to display on two radio buttons selection one for each button 如何使HTML按钮的onclick事件随机触发两个不同的函数之一? - How do I make an HTML button’s onclick event trigger one of two different functions at random? 如何让我的 SQL 结果出现在一个表中而不是 PHP/HTML 中的两个表中 - How do I get my SQL results to appear in one table instead of two within PHP/HTML 如何通过一个按钮发送两个值? - How can I send two values with one button? 如何从两个不同的表单集中选择一个单选按钮? - How do I select only one radio button from two different form sets? 如何通过1个提交按钮将html / php代码定向到两个不同的页面? - How can I get my html/php code to direct to two different pages from 1 submit button? 如何使用表单中的一个按钮提交两个不同的值? - How do I submit two different values with a single button in the form? 如何在PHP中将某个键的值从两个数组添加到一个新数组中? - How do i add values of a certain key from two arrays into one new array in PHP? 我如何只选择一个在mysql中插入两个值? - How do I insert two values in mysql with just one select?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM