psychowolvesbane Posted January 7, 2008 Share Posted January 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 $conn = mysql_connect( DELETED ); $db = mysql_select_db( DELETED ); Advice of caution: don't post those info to people Why do you have the variable $X and not use it? Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 I know, it's annoying and I don't always remember until just after. I was using it until I modified part of the checkbutton that was being displayed each time. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Okay, are you planning on using AJAX for this? If not, you need a form + submit button. Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 I've never used Ajax, and I already have the rest of the form and a submit button, this is just a small part of it. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 7, 2008 Share Posted January 7, 2008 $AColours[$X] wher can we find that array? Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 I was using $X as a counter for showing the values of an array during a while loop with $X incrementing until it reached the max number of colours. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Where did you place the bottom code? After the first one or in a new file? Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 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> Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 The validation section is above the <html> tags like usual. The checkbutton is in the <body> within my form. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Okay, so this is redundant. So in the end of all the looping, $X = $NumberOfColours = mysql_num_rows($rs). You can just put that in your validation code area. I'm thinking $X is not defined up there. So just rewrite your query and define $X. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 7, 2008 Share Posted January 7, 2008 where the form please....... Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 if(count($name) > 0) That line. What's $name? Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 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; } Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 7, 2008 Author Share Posted January 7, 2008 I have found the problem, I shouldn't have had $AColours = $_POST['Colours[]']; I should have had $AColours = $_POST['Colours']; Works now, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.