deeej Posted August 7, 2007 Share Posted August 7, 2007 Hi all, this is either really easy or a bit complicated below is the .php file I am having trouble with I have managed to get it to work but it has to be done twice. Basically I have a selection box which gets it's values from a database once this is selected the selection box's below will get the correct value from the above selection box which again comes from the database. The first selection box works by refreshing the current page and adding a variable to the file for example instead of useraddnew.php it would be useraddnew.php?maintcat=5 but the number 5 only gets set the second time you choose from the top selection I hope some one can help sorry if I explained it poorly. This is the require_once includes.php function ptypes($x, $menu_name) { //$rid = $_POST[$menu_name]; $rid = $_GET['maincat']; if ($rid != '') { $qt = "select * from ** where maincat='$rid' order by CategoryName"; $rt = mysql_query($qt) or die(mysql_error()); if(mysql_num_rows($rt) > '0') { $SelectType = "<select name=\"$menu_name\">\n\t<option value=\"\"></option>\n\t"; while($at = mysql_fetch_array($rt)) { if($x != "0") { if($at[CategoryID] == $x) { $SelectType .= "<option value=\"$at[CategoryID]\" selected>$at[CategoryName]</option>\n\t"; } else { $SelectType .= "<option value=\"$at[CategoryID]\">$at[CategoryName]</option>\n\t"; } } else { $SelectType .= "<option value=\"$at[CategoryID]\">$at[CategoryName]</option>\n\t"; } } $SelectType .= "</select>"; } } return $SelectType; } function ptypes2($x, $rid, $menu_name) { if ($rid != '') { $qt = "select * from **** where maincat='$rid' order by CategoryName"; $rt = mysql_query($qt) or die(mysql_error()); if(mysql_num_rows($rt) > '0') { $SelectType = "<select name=\"$menu_name\">\n\t<option value=\"\"></option>\n\t"; while($at = mysql_fetch_array($rt)) { if($x != "0") { if($at[CategoryID] == $x) { $SelectType .= "<option value=\"$at[CategoryID]\" selected>$at[CategoryName]</option>\n\t"; } else { $SelectType .= "<option value=\"$at[CategoryID]\">$at[CategoryName]</option>\n\t"; } } else { $SelectType .= "<option value=\"$at[CategoryID]\">$at[CategoryName]</option>\n\t"; } } $SelectType .= "</select>"; } } return $SelectType; } function mtypes($x, $menu_name) { $qt = "select * from *** order by name"; $rt = mysql_query($qt) or die(mysql_error()); if(mysql_num_rows($rt) > '0') { $SelectType = "<form action=\"$PHP_SELF?maincat=$_POST[$menu_name]\" method=\"post\" name=\"form\">"; $SelectType .= "<select name=\"$menu_name\" onChange=\"document.form.submit();\">\n\t<option value=\"$_GET[maincat]\"></option>\n\t"; while($at = mysql_fetch_array($rt)) { if($x != "0") { $rid = $_GET['maincat']; if($at[id] == $rid) { $SelectType .= "<option value=\"$at[id]\" selected>$at[name]</option>\n\t"; } else { $SelectType .= "<option value=\"$at[id]\">$at[name]</option>\n\t"; } } else { $SelectType .= "<option value=\"$at[id]\">$at[name]</option>\n\t"; } } $SelectType .= "</select>"; $SelectType .= "</form>"; } return $SelectType; } function mtypes2($x, $id, $menu_name) { $qt = "select * from *** order by name"; $rt = mysql_query($qt) or die(mysql_error()); if(mysql_num_rows($rt) > '0') { $SelectType = "<select name=\"$menu_name\">\n\t<option value=\"$_GET[maincat]\"></option>\n\t"; while($at = mysql_fetch_array($rt)) { if($x != "0") { $rid = $_GET['maincat']; if($x == $at[id]) { $SelectType .= "<option value=\"$at[id]\" selected>$at[name]</option>\n\t"; } else { $SelectType .= "<option value=\"$at[id]\">$at[name]</option>\n\t"; } } else { $SelectType .= "<option value=\"$at[id]\">$at[name]</option>\n\t"; } } $SelectType .= "</select>"; } // $SelectType .= "<a href=\"changecat.php\">Change</a>"; return $SelectType; } This is the file I am having trouble with (useraddnew.php) <? require_once("includes.php"); //get the prices $q2 = "select * from ***"; $r2 = mysql_query($q2) or die(mysql_error()); if(mysql_num_rows($r2) == '0') { echo "<br><br><font face=verdana color=red size=2><b>You need to set up the prices first!</b></font></center>"; exit(); } $sprices = "<select name=price>\n"; while($a2 = mysql_fetch_array($r2)) { $sprices .= "<option value=\"$a2[Duration]|$a2[PriorityLevel]\">$a2[PackageName] ($a2[Duration] months, $a2[PriorityName])</option>\n\t"; } $sprices .= "</select>"; if(isset($_POST[s1])) { if($_FILES['picture']['size'] > '0') { $ext_array = explode(".", $_FILES['picture']['name']); $ext = array_pop($ext_array); $ext = strtolower($ext); $allowed = array("gif", "jpg", "jpeg"); if(in_array($ext, $allowed)) { $new_picture = $t."_".$_FILES['picture']['name']; copy($_FILES['picture']['tmp_name'], "../yellow_images/".$new_picture); } } else { $new_picture = $_POST['OldLogo']; } //manage files $MyImages = array(); if($_FILES[ResumeImages][size][0] > '0') { while(list($key,$value) = each($_FILES[ResumeImages][name])) { if(!empty($value)) { $NewImageName = $t."_resume_".$value; copy($_FILES[ResumeImages][tmp_name][$key], "../***/".$NewImageName); $MyImages[] = $NewImageName; } } if(!empty($MyImages)) { $ImageStr = implode("|", $MyImages); } } if(!empty($_POST['website'])) { $NewWebsite = $_POST['website']; } else { $NewWebsite = "http://"; } $my_Manager = htmlspecialchars($_POST[Manager]); $my_address = htmlspecialchars($_POST[address]); $my_ms = htmlspecialchars($_POST[medical_school]); $my_rt = htmlspecialchars($_POST[residency_training]); $my_members = htmlspecialchars($_POST[Menu]); $lunchmenu = htmlspecialchars($_POST[lunchmenu]); $winemenu = htmlspecialchars($_POST[winemenu]); $othermenu = htmlspecialchars($_POST[othermenu]); //get the price info $pv = explode("|", $_POST['price']); //update the advertiser's record/credits $aexp = mktime(0,0,0,date(n) + $pv[0],date(j),date(Y)); $q1 = "insert into *** set username = '$_POST[NewUsername]', password = '$_POST[p1]', Manager = '$my_Manager', maincat = '$_POST[maincat]', primary_specialty = '$_POST[primary_specialty]', secondary_specialty = '$_POST[secondary_specialty]', Waiter = '$_POST[Waiter]', FirstName = '$_POST[FirstName]', LastName = '$_POST[LastName]', address = '$my_address', city = '$_POST[city]', state = '$_POST[state]', country = '$_POST[country]', phone = '$_POST[phone]', cellular = '$_POST[cellular]', pager = '$_POST[pager]', email = '$_POST[email]', website = '$_POST[website]', medical_school = '$my_ms', residency_training = '$my_rt', graduation_year = '$_POST[graduation_year]', Menu = '$my_members', lunchmenu = '$lunchmenu', othermenu = '$othermenu', winemenu = '$winemenu', Description = '$_POST[Description]', Smoking = '$_POST[smoking]', birthyear = '$_POST[birthyear]', picture = '$new_picture', ResumeImages = '$ImageStr', news = '$_POST[news]', NewsletterType = '$_POST[format]', RegDate = '$t', ExpDate = '$aexp', AccountStatus = 'active', PriorityLevel = '$pv[1]' "; mysql_query($q1); if(ereg("key 2", mysql_error())) { $error = "<span class=\"RedLink\">The username <span class=\"BlackLink\">$_POST[NewUsername]</span> is already in use!<br>Select another one, please!</span>"; unset($_POST[NewUsername]); } elseif(ereg("key 3", mysql_error())) { $error = "<span class=\"RedLink\">You are already registered!<br>Update your account, please!</span>"; unset($_POST); } else { $last = mysql_insert_id(); $_SESSION['NewAgent'] = $last; //send an email $to = $_POST['email']; $subject = "Your registration at $_SERVER[HTTP_HOST]$dir"; $message = "Hello $_POST[FirstName] $_POST[LastName],\nhere is your login information for $_SERVER[HTTP_HOST]$dir\n\nUsername: $_POST[NewUsername]\nPassword: $_POST[p1]\n\nTo login, follow this link:\nhttp://$_SERVER[HTTP_HOST]$dir/login.php\n\nThank you for your registration!"; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers .= "Content-Transfer-Encoding: 8bit\n"; $headers .= "From: $_SERVER[HTTP_HOST]$dir <$aset[ContactEmail]>\n"; $headers .= "Reply-To: $_SERVER[HTTP_HOST]$dir <$aset[ContactEmail]>\n"; $headers .= "X-Priority: 3\n"; $headers .= "X-MSMail-Priority: Normal\n"; $headers .= "X-Mailer: PHP/" . phpversion()."\n"; mail($to, $subject, $message, $headers); header("location:info.php?id=$last"); exit(); } } include_once("LeftStyles.php"); //will receive news $ch1 = "checked"; //news in HTML format $ch3 = "checked"; for($z = '1'; $z <= (5 - $i); $z++) { $ImageBlock .= "<input type=file name=\"ResumeImages[]\"><br>\n"; } if(!empty($a1[website])) { $MyWeb = $a1[website]; } else { $MyWeb = "http://"; } ?> <? if ($_GET['maincat'] != '') //If a category has been chosen { ?> <form method=post enctype="multipart/form-data" name=RegForm onsubmit="return CheckRegister();"> <table align=center class="BlackText"> <caption align=center><font face=verdana size=2><b>Add a new member</b></font><br><?=$error?></caption> <tr> <td align="right">Category:</td> <td><?=mtypes($a1['maincat'], "maincat")?> </td> </tr> <tr> <td align="right">Primary specialty:</td> <td><?=ptypes($_POST['primary_specialty'], "primary_specialty")?></td> </tr> <tr> <td align="right">Secondary specialty:</td> <td><?=ptypes($_POST['secondary_specialty'], "secondary_specialty")?></td> </tr> <tr> <td align=right>Username:</td> <td><input type="text" name="NewUsername" value="<?=$_POST[NewUsername]?>"></td> </tr> <tr> <td align=right>Password:</td> <td><input type=password name=p1></td> </tr> <tr> <td align=right>Confirm Password:</td> <td><input type=password name=p2></td> </tr> <tr> <td align=right>Manager:</td> <td><input type=text name="Manager" value="<?=$_POST['Manager']?>"></td> </tr> <tr> <td align=right>Business Name:</td> <td><input type=text name=FirstName value="<?=$_POST[FirstName]?>"></td> </tr> <tr> <td align=right>Last Name:</td> <td><input type=text name=LastName value="<?=$_POST[LastName]?>"></td> </tr> <tr> <td align=right>Address:</td> <td><input type=text name=address value="<?=$_POST[address]?>"></td> </tr> <tr> <td align=right>City:</td> <td><input type=text name=city value="<?=$_POST[city]?>"></td> </tr> <tr> <td align=right>Town:</td> <td><input type=text name=state value="<?=$_POST[state]?>"></td> </tr> <tr> <td align=right>Country:</td> <td><?=country($_POST[country]);?></td> </tr> <tr> <td align=right>Phone:</td> <td><input type=text name=phone value="<?=$_POST[phone]?>"></td> </tr> <tr> <td align=right>Email:</td> <td><input type=text name=email value="<?=$_POST[email]?>"></td> </tr> <tr> <td align=right>Website:</td> <td><input type=text name=website value="<?=$MyWeb?>"></td> </tr> <tr> <td align="right">Store Hours:</td> <td><input type="text" name="medical_school" value="<?=$_POST['medical_school']?>"></td> </tr> <tr> <td align="right">WeekEnd Hours:</td> <td><input type="text" name="residency_training" value="<?=$_POST['residency_training']?>"></td> </tr> <tr> <td align="right" valign="top">Main Menu:</td> <td><input type="text" name="Menu" value="<?=$_POST['Menu']?>"></td> </tr> <tr> <td align="right" valign="top">Wine Menu:</td> <td><input type="text" name="winemenu" value="<?=$_POST['winemenu']?>"></td> </tr> <tr> <td align="right" valign="top">Lunch Menu:</td> <td><input type="text" name="lunchmenu" value="<?=$_POST['lunchmenu']?>"></td> </tr> <tr> <td align="right" valign="top">Other Menu:</td> <td><input type="text" name="othermenu" value="<?=$_POST['othermenu']?>"></td> </tr> <tr> <td align="right" valign="top">Description:</td> <td><textarea name="Description" rows="6" cols="45"><?=$_POST['Description']?></textarea></td> </tr> <tr> <td align="right">Smoking:</td> <td><?=Smoking_status($_POST['Smoking']);?></td> </tr> <tr> <td align="right">Year Established:</td> <td><?=years("birthyear", $_POST['birthyear']);?></td> </tr> <tr> <td align=right>Your picture:</td> <td><input type=file name="picture"></td> </tr> <tr> <td align=right valign=top>Other photos:</td> <td> <?=$ImageBlock?> </td> </tr> <tr> <td align=right>Receive updates:</td> <td> <input type=radio name=news value="y" <?=$ch1?>>yes <input type=radio name=news value="n" <?=$ch2?>>no </td> </tr> <tr> <td align=right>Newsletter format:</td> <td> <input type=radio name=format value="html" <?=$ch3?>>html <input type=radio name=format value="plain" <?=$ch4?>>plain text </td> </tr> <tr> <td align=right>Select Plan:</td> <td><?=$sprices?></td> </tr> <tr> <td> </td> <td><input type=submit name=s1 value="Update"></td> </tr> </table> </form> <? } else { ?> <table align=center class="BlackText"> <caption align=center><font face=verdana size=2><b>Add a new member</b></font><br><?=$error?></caption> <tr> <td align="right">Category:</td> <td><?=mtypes($a1['maincat'], "maincat")?> </td> </tr> <tr> <td align="right">Primary specialty:</td> <td><?=ptypes($_POST['primary_specialty'], "primary_specialty")?></td> </tr> <tr> <td align="right">Secondary specialty:</td> <td><?=ptypes($_POST['secondary_specialty'], "secondary_specialty")?></td> </tr> <tr> <td align=right>Username:</td> <td><input type="text" name="NewUsername" value="<?=$_POST[NewUsername]?>"></td> </tr> <tr> <td align=right>Password:</td> <td><input type=password name=p1></td> </tr> <tr> <td align=right>Confirm Password:</td> <td><input type=password name=p2></td> </tr> <tr> <td align=right>Manager:</td> <td><input type=text name="Manager" value="<?=$_POST['Manager']?>"></td> </tr> <tr> <td align=right>Business Name:</td> <td><input type=text name=FirstName value="<?=$_POST[FirstName]?>"></td> </tr> <tr> <td align=right>Last Name:</td> <td><input type=text name=LastName value="<?=$_POST[LastName]?>"></td> </tr> <tr> <td align=right>Address:</td> <td><input type=text name=address value="<?=$_POST[address]?>"></td> </tr> <tr> <td align=right>City:</td> <td><input type=text name=city value="<?=$_POST[city]?>"></td> </tr> <tr> <td align=right>Town:</td> <td><input type=text name=state value="<?=$_POST[state]?>"></td> </tr> <tr> <td align=right>Country:</td> <td><?=country($_POST[country]);?></td> </tr> <tr> <td align=right>Phone:</td> <td><input type=text name=phone value="<?=$_POST[phone]?>"></td> </tr> <tr> <td align=right>Email:</td> <td><input type=text name=email value="<?=$_POST[email]?>"></td> </tr> <tr> <td align=right>Website:</td> <td><input type=text name=website value="<?=$MyWeb?>"></td> </tr> <tr> <td align="right">Store Hours:</td> <td><input type="text" name="medical_school" value="<?=$_POST['medical_school']?>"></td> </tr> <tr> <td align="right">WeekEnd Hours:</td> <td><input type="text" name="residency_training" value="<?=$_POST['residency_training']?>"></td> </tr> <tr> <td align="right" valign="top">Main Menu:</td> <td><input type="text" name="Menu" value="<?=$_POST['Menu']?>"></td> </tr> <tr> <td align="right" valign="top">Wine Menu:</td> <td><input type="text" name="winemenu" value="<?=$_POST['winemenu']?>"></td> </tr> <tr> <td align="right" valign="top">Lunch Menu:</td> <td><input type="text" name="lunchmenu" value="<?=$_POST['lunchmenu']?>"></td> </tr> <tr> <td align="right" valign="top">Other Menu:</td> <td><input type="text" name="othermenu" value="<?=$_POST['othermenu']?>"></td> </tr> <tr> <td align="right" valign="top">Description:</td> <td><textarea name="Description" rows="6" cols="45"><?=$_POST['Description']?></textarea></td> </tr> <tr> <td align="right">Smoking:</td> <td><?=Smoking_status($_POST['Smoking']);?></td> </tr> <tr> <td align="right">Year Established:</td> <td><?=years("birthyear", $_POST['birthyear']);?></td> </tr> <tr> <td align=right>Your picture:</td> <td><input type=file name="picture"></td> </tr> <tr> <td align=right valign=top>Other photos:</td> <td> <?=$ImageBlock?> </td> </tr> <tr> <td align=right>Receive updates:</td> <td> <input type=radio name=news value="y" <?=$ch1?>>yes <input type=radio name=news value="n" <?=$ch2?>>no </td> </tr> <tr> <td align=right>Newsletter format:</td> <td> <input type=radio name=format value="html" <?=$ch3?>>html <input type=radio name=format value="plain" <?=$ch4?>>plain text </td> </tr> <tr> <td align=right>Select Plan:</td> <td><?=$sprices?></td> </tr> <tr> <td> </td> <td><input type=submit name=s1 value="Update"></td> </tr> </table> <? } ?> Hope some one can help thanks! Quote Link to comment https://forums.phpfreaks.com/topic/63769-selection-box-via-selection/ Share on other sites More sharing options...
jvrothjr Posted August 7, 2007 Share Posted August 7, 2007 echo "<form name='form1' method='post' action='$PHP_SELF'>"; echo "<select name='myselect' onchange=form1.submit()>"; while($row=mysql_fetch_assoc($dropdownlist)) { echo "<option value=".$row[iD]; if ($_POST[myselect]==$row[iD]) {echo " SELECTED";} echo ">".$row[manufacturer]."</a></option>"; } echo "</select><br /><br />"; echo "</form>"; did not read your whole code but it sound like you want the first select to define the next select box and so on and that would would done via onchange option of the select box Quote Link to comment https://forums.phpfreaks.com/topic/63769-selection-box-via-selection/#findComment-317801 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.