Jump to content

[SOLVED] Check Button Validation Help


psychowolvesbane

Recommended Posts

I have this Check Button form:

 


    <fieldset style="padding: 2">
     <legend>Available Colours</legend>

     <table border="1"><tr>

      <?php
      //Establish a connection to the Database

      $conn = mysql_connect('Deleted','Deleted','Deleted');

      $db = mysql_select_db('Deleted', $conn);

      $sql = "SELECT AvailableColours FROM Colours ORDER BY AvailableColours";
   
      $rs = mysql_query($sql, $conn) or die(mysql_error());

      $NumberOfColours = mysql_num_rows($rs);
      
      $X=0;

      $counter = 0;

      if ($result || (mysql_num_rows($rs) > 0))
      {
         while ($row = mysql_fetch_assoc($rs)) 
         {    
            if($counter%9==0&&$counter!=0) echo "</tr><tr>";
            echo "<td><img src='/images/colours/{$row['AvailableColours']}.gif' /><br />";
            echo "<td><input type='checkbox' name='Colours[]' value='{$row['AvailableColours']}'></td>";
            echo "</td>";
            ++$X;
            ++$counter;
         }
      }
      echo "</tr></table>";
     
     mysql_close($conn); 
     ?>
    </legend>
   </fieldset>

 

That looks like this: http://i110.photobucket.com/albums/n82/psychofox19/example.jpg

 

I have this validation atm but I don't know what is wrong with it as it doesn't display anything in the variable $AvailableColours

 

if($_POST['SubmitB'] =="Submit")
{

   $AColours[] = $_POST['Colours[]'];

   if(count($name) > 0)
   {
      foreach($name AS $names)
      {
         $Valid_AColours=True;
         $AvailableColours .=$AColours[$X]."?";
      }
   }
   else 
   {
      $Valid_AColours=False;
   }
}

echo $AvailableColours;
?>

 

I essentially want the record from the database assigned to each check button, and when that check button has been selected I want it concatenate all the records from all the selected buttons into a single variable with a ?(or any other appropriate character) in between each one so I can do as special char function on it later in a different part of the site to retrieve each record.

 

E.g.

 

Ash?Black?Red?White?

 

That is what $AvailabelColours should be displaying but it isn't.

Link to comment
https://forums.phpfreaks.com/topic/84794-solved-check-button-validation-help/
Share on other sites

Okay code without the $X in.

 

Validation section

<?php

if($_POST['SubmitB'] =="Submit")
{

   $AColours = $_POST['Colours[]'];

   if(count($name) > 0)
   {
      foreach($name AS $names)
      {
         $Valid_AColours=True;
         $AvailableColours .=$AColours."?";
      }
   }
   else 
   {
      $Valid_AColours=False;
   }
}

echo $AvailableColours;
?>

 

CheckButton section

    <fieldset style="padding: 2">
     <legend>Available Colours</legend>

     <table border="1"><tr>
     <?php
Connection details...

      $sql = "SELECT AvailableColours FROM Colours ORDER BY AvailableColours";
   
      $rs = mysql_query($sql, $conn) or die(mysql_error());

      $NumberOfColours = mysql_num_rows($rs);

      $counter = 0;

      if ($result || (mysql_num_rows($rs) > 0))
      {
         while ($row = mysql_fetch_assoc($rs)) 
         {    
            if($counter%9==0&&$counter!=0) echo "</tr><tr>";
            echo "<td><img src='/images/colours/{$row['AvailableColours']}.gif' /><br />";
            echo "<td><input type='checkbox' name='Colours[]' value='{$row['AvailableColours']}'></td>";
            echo "</td>";
            ++$X;
            ++$counter;
         }
      }
      echo "</tr></table>";
     
     mysql_close($conn); 
     ?>
    </legend>
   </fieldset>

The whole thing:

 

<?php

if($_POST['SubmitB'] =="Submit")
{

   $AColours = $_POST['Colours[]'];
   echo $AColours;

   if(count($name) > 0)
   {
      foreach($name AS $names)
      {
         $Valid_AColours=True;
         $AvailableColours .=$AColours."?";
      }
   }
   else 
   {
      $Valid_AColours=False;
   }
}

echo $AvailableColours;
?>
<html>
<head>
  <title>Clothing Line</title>
  <link href="stylesheetCL.css" rel="stylesheet">
  <?php require('jscript.inc') ?>
</head>


</head>

<body>

  <?php require('menu.inc') ?>


<div style="position:absolute; top:75px; left:200px; width:550px">

<?php
if($_POST['SubmitB'] != "Submit")
{
?>
   <form method="post" enctype="multipart/form-data" action='add_product_form.php'/>
    <br>
    Clothing Code: 
    <br>
    <input type="text" name="ClothingCode"/>
    <br>
    <br>
    Description: 
    <br>
    <input type="text" name="Description"/>
    <br>
    <br>
    
    Item Type: 
    <br>
    <select name="ItemType"/>
    
<?php
    //Establish a connection to the Database

    $conn = mysql_connect('Deleted','Deleted','Deleted');

    $db = mysql_select_db('Deleted', $conn);

    $sql = "SELECT ItemType FROM ItemType ORDER BY ItemType";
  
    $rs = mysql_query($sql, $conn) or die(mysql_error());
    
    $X=0;
   
    while($row = mysql_fetch_array($rs))
    {
       echo"<option value='$X'>{$row['ItemType']}</option>";
       $X++;
    }
    mysql_close($conn);
    
?>
    </select>

    <br>
    <br>
    Price: 
    <br>
    <input type="number" name="Price"/>
    <br>
    <br>
    Clothing Image: 
    <br>
    <input type="file" name="ClothingImage">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
    <br>
    <br>
    <fieldset style="padding: 2">
     <legend>Available Sizes
     </legend>
     <table border="1" id="Sizes">
<tr>
	<td width="35">S</td>
	<td width="35">M</td>
	<td width="35">L</td>
	<td width="35">XL </td>
	<td width="35">XXL</td>
	<td width="35">3XL</td>
</tr>
<tr>
	<td width="35"><input type="checkbox" name="Small" value="ON"></td>
	<td width="35"><input type="checkbox" name="Med" value="ON"></td>
	<td width="35"><input type="checkbox" name="Large" value="ON"></td>
	<td width="35"><input type="checkbox" name="XL" value="ON"></td>
	<td width="35"><input type="checkbox" name="XXL" value="ON"></td>
	<td width="35"><input type="checkbox" name="3XL" value="ON"></td>
    	</tr>
     </table>
    </fieldset>
    <br>

    <fieldset style="padding: 2">
     <legend>Available Colours</legend>

     <table border="1"><tr>

      <?php
      //Establish a connection to the Database

      $conn = mysql_connect('Deleted','Deleted','Deleted');

      $db = mysql_select_db('Deleted', $conn);

      $sql = "SELECT AvailableColours FROM Colours ORDER BY AvailableColours";
   
      $rs = mysql_query($sql, $conn) or die(mysql_error());

      $NumberOfColours = mysql_num_rows($rs);

      $counter = 0;

      if ($result || (mysql_num_rows($rs) > 0))
      {
         while ($row = mysql_fetch_assoc($rs)) 
         {    
            if($counter%9==0&&$counter!=0) echo "</tr><tr>";
            echo "<td><img src='/images/colours/{$row['AvailableColours']}.gif' /><br />";
            echo "<td><input type='checkbox' name='Colours[]' value='{$row['AvailableColours']}'></td>";
            echo "</td>";
            ++$counter;
         }
      }
      echo "</tr></table>";
     
     mysql_close($conn); 
     ?>
    </legend>
   </fieldset>
   <br> 
   <br>
<input type="submit" name="SubmitB" value="Submit"/>
</form>

<?php
}
?>
</div>
</body>
</html>

 

All I want to work on atm is the Available Colours section, the text boxes, file upload and the other check button group can wait.

Part of a code I used before and forgot to change the variable to $AColours.

 

Still didn't work though

 

   $AColours = $_POST['Colours[]'];
   echo $AColours;

   if(count($AColours) > 0)
   {
      foreach($AColours AS $Colours)
      {
         $Valid_AColours=True;
         $AvailableColours .=$Colours."?";
      }
   }
   else 
   {
      $Valid_AColours=False;
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.