Forum Moderators: coopster
I would like the user to write its choices into a 4th table that is made just to save these choices
The table is: cat1 - cat2 - cat3
When the button is presset that refferes to a insert.php file the information is written to the database but in the following format:
Example:
1 6 Chicago
Would anyone like to help me with getting the information into the dbase so that the first 2 options also are put there in words instead of numbers?
Thanks a lot!
<?php
$dbservertype='mysql';
$servername='localhost';
$dbusername='#*$!#*$!';
$dbpassword='#*$!#*$!';
$dbname='#*$!#*$!';
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd3.php?cat=' + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
self.location='dd3.php?cat=' + val + '&cat3=' + val2 ;
}
</script>
<style type="text/css">
<!--
.stil1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<p>
<?
$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
$cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id=$cat order by subcategory");
}else{$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"); }
$cat3=$HTTP_GET_VARS['cat3'];
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id=$cat3 order by subcat2");
}else{$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"); }
echo "<form method=post name=f1 action='insert_teknik.php'>";
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";}
}
echo "</select>";
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['subcat_id']==@$cat3){echo "<option selected value='$noticia[subcat_id]'>$noticia[subcategory]</option>"."<BR>";}
else{echo "<option value='$noticia[subcat_id]'>$noticia[subcategory]</option>";}
}
echo "</select>";
echo "<select name='subcat3' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3)) {
echo "<option value='$noticia[subcat2]'>$noticia[subcat2]</option>";
}
echo "</select>";
echo "<input type='submit' value='Skicka'>";
echo "</form>";
?>
</p>
<label>
</label>
<p> </p>
<p> </p>
</body>
</html>
[edited by: Daxman23 at 3:35 pm (utc) on Nov. 22, 2007]
$cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off
Seeing as my bleeding eyes are getting in the way of me looking through all of your code, could you explain how your cat, subcat and subcat3 (the name's of your select tags) relate to your cat1-cat2-cat3 from your sql table?
You may also want to look at -
<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"
To be honest i have tried every single way i can come up with to populate a dropdown box with tables in the database and write "users choice" to a seperate table.
At this point i am pulling my hair out and feel like killing somebody just to get rid of my frustration:)
Can you (or anyone else) PLEASE give me an example of how to accomplish this?
I get the dropdown to work and get the form to call the insert.php file. I also see a new row in the table but the row is either empty or numeric and i need it to be alphabetic.
Your help is greatly appriciated.
//Daxman
[edited by: Daxman23 at 9:39 am (utc) on Nov. 23, 2007]
Assuming this is the html that you are working with -
You already have the code for generating similar html in your post, so i haven't included all of the php needed to get to this.
<select name="yourInput">
<option value="yourValue1">yourValue1</option>
<option value="yourValue2">YourValue2</option>
</select>
<select name="userInput">
<option value="userValue1">userValue1</option>
<option value="userValue2">userValue2</option>
</select>
array (
yourInput => yourValue2
userInput => userValue1
)
<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"
<option selected value='$noticia2[category]'>$noticia2[category]</option>"
<disclaimer>
I still haven't read through all of your code...so this may not be exactly what you want. However hopefully it will get you closer then you could repost less code and we could work from there ;)