1

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

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.

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.

Any light shed on this would be hugely appreciated.

Thanks in advance.

3 Answers 3

2

You are missing an = in your HTML:

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

should be:

<input type="text" name="membership">
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my days, how easy that was. No syntax error or nothing came up! I must have gone over the code twenty times, clearly missing that out each time. I only have 8 reputation so unfortunately I cannot +1 your response.
1

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

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.

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 Comments

Many thanks for this, it was simply a '=' was missing in the membership form. How ever, I will take into consideration all of the answers to help improve my programming skills.
Sure, glad that worked. One thing you may want to do is space/indent your code a little so it's easier for you (and others) to read. You can run your code through phpformatter.com until you get the hang of it.
Thanks for this g_thorn, i'll put this into practice when ever else I ask for support.
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 Comment

Many thanks for this, I will take it into consideration to help increase my programming knowledge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.