Welcome to WebmasterWorld Guest from 50.17.16.177

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Passing and getting variables through an array and $ POST

     
10:24 pm on Apr 9, 2012 (gmt 0)

New User

joined:Apr 9, 2012
posts:17
votes: 0


I am trying to build a form in a while loop. It has check boxes and and combo boxes.


<form name="Getting_Spells2" method="post" action="free-app3.php">
<?php
//Including the connection information
include "config.php";

//connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die("Could not connect to MySQL");

//select the database
mysql_select_db($database) or die ("Could not select database");

//Put the result into an array
$result = mysql_query ("SELECT DISTINCT spell_name FROM spells WHERE spell_class = '".$class."' AND spec = '".$spec."' AND spell_level BETWEEN '".$level_low."' AND '".$level."'") or die('Error getting array form spells table '.mysql_error ());

while($row = mysql_fetch_array($result))
{
$spell_id=$row["spell_id"];
$spell_name=$row["spell_name"];
$class=$row["spell_class"];
$level=$row["spell_level"];
$knowledge=$row["spell_knowledge"];
$mindmg=$row["min_dmg"];
$maxdmg=$row["max_dmg"];
$mindot=$row["min_dot"];
$maxdot=$row["max_dot"];
$dot_ticks=$row["dot_ticks"];
$cast_time=$row["cast_time"];
$duration=$row["duration"];
$recovery=$row["recovery"];
$recast=$row["recast"];
$triggers=$row["triggers"];
$avg_dmg=$row["avg_dmg"];
$instant_time=$row["instant_time"];
$total_cast_time=$row["total_cast_time"];
$instant_dps=$row["instant_dps"];
$dps=$row["dps"];
$spec=$row["spec"];


echo "<input type=\"checkbox\" name=\"spell_name2[]\" value=\"".$spell_name."\"&nbsp;&nbsp;&nbsp;>";
echo $spell_name."&nbsp;&nbsp;&nbsp;". $class ."<BR>";

//Including the connection information
include "config.php";

//connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die("Could not connect to MySQL");

//select the database
mysql_select_db($database) or die ("Could not select database");

//Get the spell knowledge for the row
$query2 = mysql_query ("SELECT knowledge FROM spell_knowledge ORDER By knowledge_id ASC") or die(mysql_error());

//Put the result into an array
$result2 = mysql_fetch_array($query2);

if ($result2) {
$rowno = 0;

echo("<select name=\"knowledge2[]\" size=\"1\" id=\"knowledge2[]\"><BR><BR>");

while ($row = mysql_fetch_assoc($query2)) {

$rowno++;

foreach($row as $_k=>$_v) {

echo("<option value=\"" .$_v. "\">" .$_v. "");

}

}
echo("</select>");
}
else {
# Print error
echo "<b>Query2 failed: Knowledge</b><br>".mysql_error();
}
echo "<br />";


}
?>
<input type="submit" name="Submit" value="Submit">
</form><br>


When I go to the next page it gives me the correct values for the checkboxes but gives me ALL of the values for the comboboxes not just the ones that were checked.

How do I get it to give me just the values form the comboboxes for the rows that were checked?

Any help would be greatly appreciated!

MM
12:28 pm on Apr 10, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:June 6, 2006
posts:97
votes: 0


Should you have a WHERE statement included in this?


$query2 = mysql_query ("SELECT knowledge FROM spell_knowledge WHERE column = checkedbox_value ORDER By knowledge_id ASC") or die(mysql_error());
4:11 am on Apr 11, 2012 (gmt 0)

New User

joined:Apr 9, 2012
posts:17
votes: 0


No, But I figured out a way around it. Thank you for trying :) Off to tackle my next hurdle!

MM