在while循环中,文本字段不添加到数组

时间:2022-03-31 22:43:49

I have 2 columns on my add_membership page. The left column is 'Memberships added' and the right column is 'Memberships too add'.

我的add_membership页面上有2列。左栏是“会员已添加”,右栏是“会员已添加”。

The code to present the 'memberships to add' is:

呈现“要添加的成员资格”的代码是:

$credit=mysql_query("SELECT * FROM credit");
while($rowc=mysql_fetch_assoc($credit)){
$credit_id=$rowc['credit_id'];
if(in_array($credit_id, $_SESSION['pa']))
{}else{
$url_log=$rowc['logo_url'];
$name=$rowc['name'];
?>
<form action="#" method="post">
<div class="text_right"><input type="submit" value="Add" 
name="asubmit" class="search_input_submit" /></div>
<?php echo  "<img src='$url_log' width='50' height='50' alt='$name' title='$name'>"; ?>
<input type="checkbox" value="<?php echo $credit_id; ?>" name="credit_id" />
<strong><?php echo $name; ?></strong><br />
Membership Number:<input type="text" name"membership">
</form><br /><br />
<?php
}
}
?>

As you can see the Membership number input.

如您所见,可以看到会员编号输入。

This is the code i've been trying to get to work to add the Membership Number:

这是我一直试图添加会员号码的代码:

<?php 
if($_POST['asubmit']){
$credit_id_add=$_POST['credit_id'];
$membership=$_POST['membership'];
mysql_query("INSERT INTO accreditation VALUES(NULL, $lid, $credit_id_add, 
'$membership','0' )");
echo $membership ;
$credit_id_add=null;
$referer = $_SERVER['HTTP_REFERER'];
echo "<meta http-equiv='refresh' content='1; url=$referer'> ";  
}
?>

I have 'echo'd' the variables I need to save and they all appear except for the 'Membership' which is why the error is occurring because it's trying to find the $membership value.

我已经'回应'我需要保存的变量,除了'Membership'之外它们都出现了,这就是为什么错误发生的原因,因为它试图找到$ membership值。

For the top section of the code, I have had to include the Credit ID into a checkbox as it doesn't seem to work by me just echo'ing for the $_POST to pick up, or putting it in a hidden text field.

对于代码的顶部部分,我必须将Credit ID包含在一个复选框中,因为它似乎不起作用,只需回显$ _POST来拾取或将其放入隐藏文本字段中。

Any light shed on this would be hugely appreciated.

任何关于此的光线都将受到极大的赞赏。

Thanks in advance.

提前致谢。

3 个解决方案

#1


2  

You are missing an = in your HTML:

你在HTML中缺少一个=:

<input type="text" name"membership">

should be:

应该:

<input type="text" name="membership">

#2


1  

If the first block of code is being used, you're also not closing the else condition:

如果正在使用第一个代码块,那么您也没有关闭else条件:

else{
$url_log=$rowc['logo_url'];
$name=$rowc['name'];
?>

Should be:

应该:

else {
    $url_log = $rowc['logo_url'];
    $name = $rowc['name'];
}
?>

There should also be a } before the closing PHP tag to close the while loop. I'm not sure if that was just missed in a copy/paste from your page, but if it's in your code, fixing that will help.

在关闭PHP标记之前还应该有一个}来关闭while循环。我不确定是否只是在页面的复制/粘贴中错过了,但如果它在您的代码中,那么修复它将有所帮助。

Like this:

喜欢这个:

<?php
  $credit = mysql_query("SELECT * FROM credit");
  while ($rowc = mysql_fetch_assoc($credit)) {
      $credit_id = $rowc['credit_id'];
      if (!in_array($credit_id, $_SESSION['pa'])) {
          $url_log = $rowc['logo_url'];
          $name = $rowc['name'];
      }
  }
?>

#3


0  

General tip:

一般提示:

Instead of doing

而不是做

if (some condition you only need when it's false) {
} else {
   ... do stuff here ...
}

just write

写吧

if (!some condition...) {
   ... do stuff here ...
}

Note the !, which is a logical negation, aka "not". It makes it far more explicit that you only want to deal with "false" conditions, and didn't just forget to fill in the "true" portion.

注意!,这是一个逻辑否定,又名“不”。它更明确地表明你只想处理“错误”条件,并且不要忘记填写“真实”部分。

#1


2  

You are missing an = in your HTML:

你在HTML中缺少一个=:

<input type="text" name"membership">

should be:

应该:

<input type="text" name="membership">

#2


1  

If the first block of code is being used, you're also not closing the else condition:

如果正在使用第一个代码块,那么您也没有关闭else条件:

else{
$url_log=$rowc['logo_url'];
$name=$rowc['name'];
?>

Should be:

应该:

else {
    $url_log = $rowc['logo_url'];
    $name = $rowc['name'];
}
?>

There should also be a } before the closing PHP tag to close the while loop. I'm not sure if that was just missed in a copy/paste from your page, but if it's in your code, fixing that will help.

在关闭PHP标记之前还应该有一个}来关闭while循环。我不确定是否只是在页面的复制/粘贴中错过了,但如果它在您的代码中,那么修复它将有所帮助。

Like this:

喜欢这个:

<?php
  $credit = mysql_query("SELECT * FROM credit");
  while ($rowc = mysql_fetch_assoc($credit)) {
      $credit_id = $rowc['credit_id'];
      if (!in_array($credit_id, $_SESSION['pa'])) {
          $url_log = $rowc['logo_url'];
          $name = $rowc['name'];
      }
  }
?>

#3


0  

General tip:

一般提示:

Instead of doing

而不是做

if (some condition you only need when it's false) {
} else {
   ... do stuff here ...
}

just write

写吧

if (!some condition...) {
   ... do stuff here ...
}

Note the !, which is a logical negation, aka "not". It makes it far more explicit that you only want to deal with "false" conditions, and didn't just forget to fill in the "true" portion.

注意!,这是一个逻辑否定,又名“不”。它更明确地表明你只想处理“错误”条件,并且不要忘记填写“真实”部分。