Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在html之间传递变量(php)_Javascript_Php_Html_Css - Fatal编程技术网

Javascript 在html之间传递变量(php)

Javascript 在html之间传递变量(php),javascript,php,html,css,Javascript,Php,Html,Css,我正在尝试在表单中传递action标记中的参数,就像我在href标记中所做的那样,但这不起作用。我能知道为什么吗?或者我应该在表单中使用href标记,这会覆盖表单中的操作吗? 这是我的密码: <!DOCTYPE html> <html lang="en"> <?php $ty=$_GET['param']; $name=$_GET['param1']; if($ty=='teacher') { $web = "<a hre

我正在尝试在表单中传递action标记中的参数,就像我在href标记中所做的那样,但这不起作用。我能知道为什么吗?或者我应该在表单中使用href标记,这会覆盖表单中的操作吗? 这是我的密码:

<!DOCTYPE html>
<html lang="en">
<?php 
   $ty=$_GET['param'];
   $name=$_GET['param1'];
   if($ty=='teacher')
   {
      $web = "<a href='teacherrepute.php?a=$name'>My repute score</a>"; 
      $rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
      $blk = "<a href='newblocktryteacher.php?a=$name'>Block this site</a>";
      $unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
   }
   else
   {
      $web = "<a href='pupilrepute.php?a=$name'>My repute score</a>"; 
      $rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
      $blk = "<a href='newblocktrypupil.php?a=$name'>Block this site</a>";
      $unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site";
   }
   // $type=$_GET['param2'];
   $courseA='A';
   $courseB='B';
?>
<body>
   <a href="reporttable.html"><?php echo $rep; ?></a>
   <FORM action = <?php echo $blk; ?>  method ="POST";>
      Block : <input type ="text" name = "url" /></br>
      <br>
      <input type="submit" value="block" />   
      <br>
   </FORM>
</body>
</html>


您的
$blk
不是有效的操作表单,因为它是
标记(链接)。因此,
$blk
应该是
newblocktrypupil.php?a=$name'

您的
$blk
格式不适合

正如你所看到的,这是不正确的。您所需要的只是URL本身。此外,请删除
“POST”

1)后面的分号,因为您已经基于条件创建了链接,然后可以直接在标记中回显该变量。e、 g

 <?php echo $rep; ?>

2) 您只需传递脚本名称,而不是在表单操作中传递html。e、 g

newblocktrytacher.php?a=somename或newblocktrypupil.php?a=somename

基于这两点,您的代码将

<!DOCTYPE html>
<html lang="en">
<?php 
   $ty=$_GET['param'];
   $name=$_GET['param1'];
   if($ty=='teacher')
   {
      $web = "<a href='teacherrepute.php?a=$name'>My repute score</a>"; 
      $rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
      $blk = "newblocktryteacher.php?a=$name";
      $unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
   }
   else
   {
      $web = "<a href='pupilrepute.php?a=$name'>My repute score</a>"; 
      $rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
      $blk = "newblocktrypupil.php?a=$name";
      $unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site</a>";
   }
   // $type=$_GET['param2'];
   $courseA='A';
   $courseB='B';
?>
<body>

   <?php echo $rep; ?>
   <form action="<?php echo $blk; ?>" method="POST">
      Block : <input type="text" name="url" /></br>
      <br>
      <input type="submit" value="block" />   
      <br>
   </form>
</body>
</html>


action属性采用url字符串,而不是html字符串,例如,它应该看起来像
action=“pupilreported.php?a=somename”
@PatrickEvans我不想这样做,因为我运行的php是根据用户决定的,所以我放了一个if-else语句来决定!因此,我必须以u-see的形式传递一个参数,因此单击按钮将根据用户类别启动php我知道,我不是说要硬编码操作,我是说使用您当前的代码,您的action属性最终看起来像
action=
,这是invalid@PatrickEvans那你建议我怎么做?为什么OP“试试这个”?请对您所做的以及您为什么这样做的原因进行解释,不仅是为了OP,而且是为了未来的访客。@Rizier123在阅读了我的所有评论后,您能给出一个答案吗?我必须将用户分类为教师或学生,然后使用适当的php,我不能将其硬编码为教师(即newblocktrytacher.php?a='bob')你没抓住重点。您可以使用PHP作为名称。问题是您在
操作
标记中包含
标记,这毫无意义。
 <?php echo $rep; ?>
<!DOCTYPE html>
<html lang="en">
<?php 
   $ty=$_GET['param'];
   $name=$_GET['param1'];
   if($ty=='teacher')
   {
      $web = "<a href='teacherrepute.php?a=$name'>My repute score</a>"; 
      $rep = "<a href='teacherreported.php?a=$name'>My reported sites</a>";
      $blk = "newblocktryteacher.php?a=$name";
      $unblk = "<a href='newtryunblockteacher.php?a=$name>Unblock this site";
   }
   else
   {
      $web = "<a href='pupilrepute.php?a=$name'>My repute score</a>"; 
      $rep = "<a href='pupilreported.php?a=$name'>My reported sites</a>";
      $blk = "newblocktrypupil.php?a=$name";
      $unblk = "<a href='newtryunblockpupil.php?a=$name>Unblock this site</a>";
   }
   // $type=$_GET['param2'];
   $courseA='A';
   $courseB='B';
?>
<body>

   <?php echo $rep; ?>
   <form action="<?php echo $blk; ?>" method="POST">
      Block : <input type="text" name="url" /></br>
      <br>
      <input type="submit" value="block" />   
      <br>
   </form>
</body>
</html>