473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dynamic dropdown menu to database

Hey all,

Heres the situation:
I have a form page that needs to have multiple drop down menus that is pulling their options from a database. Right now I have one working out of 3. So that is one issue, now the issue that I am having with the one that is working, is that it is not writing anything to the database. No matter what you select, the database is empty. Any help would be sweet.
So here is the form page, with just a few text fields, and the one dynamic drop down that is working:

[PHP]<?PHP
//this code is bringing in the values for the dropdown.
$sql="SELECT * FROM category";
$result=mysql_query($sql);
$options="";

while ($row=mysql_fetch_array($result)) {
$id=$row["cat"];
$cat=$row["category"];
$options.="<OPTION VALUE=\"$id\">".$cat.'</option>';

}
?>
<html>
<head>
<title>Manage Spots</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><form action="process.php" method="post" enctype="multipart/form-data">
<p>Title
<input type="text" name="Title">
</p>
<p>Spot #
<input type="text" name="Spot_Number">
</p>
<p>Series
<select name="Series" id="Series">
<option value="test">test</option>
</select>
&nbsp;&nbsp; <a href="series_edit.php">Manage Series</a> </p>
<p>Date
<input type="text" name="Creation_Date">
</p>
<p>Category #1
<select name="Category_One" id="Category_One">
<option value="0"><? echo $options ?> </option>
</select>
&nbsp;&nbsp; <a href="category_edit.php">Manage Categories</a>
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>[/PHP]

Then I have it going to a page called process.php that just inserts everything into the database, here is the page if that helps:

[PHP]<?PHP
$dbh=mysql_connect ("localhost", "", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("snmwebde_rynodb");
$Title=$_POST{'Title'};
$Spot_Number=$_POST{'Spot_Number'};
$Series=$_POST{'Series'};
$Creation_Date=$_POST{'Creation_Date'};
$Category_One=$_POST{'Category_One'};
?>
<?PHP
$query = "insert into spots values
('$Title','$Spot_Number','$Series','$Creation_Date ','$Category_One')";
$result = mysql_query($query);
?>
Entry added!!<br>
To view database click <a href="viewdb.php">here</a>.

</body>
</html>[/PHP]

Any help would be really great, seeing if i fix these 2 problems, I am done with this project. Thanks again
Nov 20 '06 #1
7 4238
ronverdonk
4,258 Expert 4TB
Your <option> statement is screwed up. Statement [php]<option value="0"><? echo $options ?> </option>[/php] generates [php]<option value="0">
<option value=xx>yy</option>
<option value=aa>bb</option>
</option>[/php]
I cannot predict the result of this. Fix that first and see the results.

Ronald :cool:
Nov 20 '06 #2
ya i noticed that after i posted, still nothing gets posted to the database for that field
Nov 20 '06 #3
ronverdonk
4,258 Expert 4TB
Hey all,

Heres the situation:
I have a form page that needs to have multiple drop down menus that is pulling their options from a database. Right now I have one working out of 3. So that is one issue, now the issue that I am having with the one that is working, is that it is not writing anything to the database. No matter what you select, the database is empty. Any help would be sweet.
So here is the form page, with just a few text fields, and the one dynamic drop down that is working:

[PHP]<?PHP
//this code is bringing in the values for the dropdown.
$sql="SELECT * FROM category";
$result=mysql_query($sql);
$options="";

while ($row=mysql_fetch_array($result)) {
$id=$row["cat"];
$cat=$row["category"];
$options.="<OPTION VALUE=\"$id\">".$cat.'</option>';

}
?>
<html>
<head>
<title>Manage Spots</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><form action="process.php" method="post" enctype="multipart/form-data">
<p>Title
<input type="text" name="Title">
</p>
<p>Spot #
<input type="text" name="Spot_Number">
</p>
<p>Series
<select name="Series" id="Series">
<option value="test">test</option>
</select>
&nbsp;&nbsp; <a href="series_edit.php">Manage Series</a> </p>
<p>Date
<input type="text" name="Creation_Date">
</p>
<p>Category #1
<select name="Category_One" id="Category_One">
<option value="0"><? echo $options ?> </option>
</select>
&nbsp;&nbsp; <a href="category_edit.php">Manage Categories</a>
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>[/PHP]

Then I have it going to a page called process.php that just inserts everything into the database, here is the page if that helps:

[PHP]<?PHP
$dbh=mysql_connect ("localhost", "", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("snmwebde_rynodb");
$Title=$_POST{'Title'};
$Spot_Number=$_POST{'Spot_Number'};
$Series=$_POST{'Series'};
$Creation_Date=$_POST{'Creation_Date'};
$Category_One=$_POST{'Category_One'};
?>
<?PHP
$query = "insert into spots values
('$Title','$Spot_Number','$Series','$Creation_Date ','$Category_One')";
$result = mysql_query($query);
?>
Entry added!!<br>
To view database click <a href="viewdb.php">here</a>.

</body>
</html>[/PHP]

Any help would be really great, seeing if i fix these 2 problems, I am done with this project. Thanks again
Have you investigated any errors coming out of the select, like this:
[php]$result=mysql_query($sql)
or die("Select query error: " . mysql_error());[/php]
At least you know then what the actual problem might be and where to look further.

Ronald :cool:
Nov 20 '06 #4
see there are no errors because everything else will write to the database, i just don't know if its even possible to take info like that and put it into a database
Nov 20 '06 #5
ronverdonk
4,258 Expert 4TB
Have you print_r the $_POST array to see if anything is passed in Category_One?

Ronald :cool:
Nov 20 '06 #6
Have you print_r the $_POST array to see if anything is passed in Category_One?

Ronald :cool:
how do i do that?
Nov 20 '06 #7
ronverdonk
4,258 Expert 4TB
As the first statements in your script:[php]<?php
echo '<pre>'; // makes it better readable on screen
print_r($_POST);[/php]This will show you all values passed t and stored in the $_POST associative array.

Ronald :cool:
Nov 21 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jorntk | last post by:
How can i make a drop down menu that are dynamiclly generated base on the value selected in another drop down menu? thanks nad regards Jorn
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
7
by: Jeff Uchtman | last post by:
I know I have done this but my mind is fried. I have a dynamic dropdown in a form. I need to pull both the dynamic dropdown's ID and name listed in the dropdown. Need a little help with grey...
1
by: sydd | last post by:
Hi, I was wondering if it's possible to create a dynamic dropdown menu from this code. if($rs->getNumRows() > 0){ $intProjectCount = 1; $htmlOut ="<table width='100%' border='0'...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.