Hey there
I am using phpMyAdmin and MySQL to develop a dbase application.
I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database. The code for this is as follows: - $sql3="SELECT ID, UploadDate FROM Telkom";
-
$result2=mysql_query($sql3);
-
$options="";
-
-
while ($row=mysql_fetch_array($result2)) {
-
-
$id=$row["ID"];
-
$date=$row["UploadDate"];
-
$options.="<OPTION VALUE=\"$id\">".$date;
-
-
The code for the actual dropdown menu is as follows:
-
-
<form name="selectdata" action="select_telkom_data.php" method="post">
-
<SELECT NAME="thedate">
-
<OPTION>Choose
-
<?=$options?>
-
</SELECT>
-
<input type="submit" name="Submit" value="Go">
-
</form>
-
-
As you can see there is an additional php script (select_telkom_data.php). This script is supposed to check the $date variable against the UploadDate table and then return the correct record based on the date the user has selected in the dropdown menu.
-
-
The code for select_telkom_data.php looks like this:
-
-
<?php
-
-
include "admin/dataw.php";
-
include("global.inc.php");
-
$sysadminemail = "webmaster@dtmsi.org";
-
-
process_login();
-
die();
-
-
-
function process_login() {
-
global $dbhost;
-
global $dbuser;
-
global $dbpass;
-
global $db;
-
-
// define homepage and text variables
-
global $homepage;
-
global $homedir;
-
global $sysadminemail;
-
global $userstable;
-
-
-
$date=$_POST['thedate'];
-
$link = mysql_connect("$dbhost", "$dbuser", "$dbpass")
-
or die('Could not connect: ' . mysql_error());
-
echo 'Connected successfully';
-
mysql_select_db("$db") or die('Could not select database');
-
-
$query = "SELECT * FROM Telkom WHERE UploadDate='$date' ";
-
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
-
-
-
$num_rows = mysql_num_rows($result);
-
$row = mysql_fetch_array($result);
-
-
-
// test -- does the date exist
-
if ($num_rows < 1) {
-
print "<HTML>";
-
print "<HEAD>";
-
print "<TITLE>";
-
print "Error";
-
print "</TITLE>";
-
print "<BODY>";
-
print "<CENTER>";
-
print "<B><CENTER>Sorry - no records exist. ";
-
-
-
}
-
else {
-
-
-
include("show_telkom_data.php");
-
-
mysql_close($link);
-
}
-
-
-
}
-
-
?>
[Please use CODE tags when posting source code. Thanks! --pbmods]
The script connects to the database, but it doesn't return any records from the Telkom table. In other words, all I get is the message 'Sorry - no records exist'.
What am I doing wrong?
Thanks guys!
Panna
4 3408
The value that you are getting from your selection is not the UploadDate, it's the id. The UploadDate is just the label of the option, not the value of it.
if you print_r($_POST), you'll see the values that are being passed from the form.
The value that you are getting from your selection is not the UploadDate, it's the id. The UploadDate is just the label of the option, not the value of it.
if you print_r($_POST), you'll see the values that are being passed from the form.
ok, thanks very much! Just one more question though: I'm not entirely sure what to change to make it work. I would REALLY appreciate if you could help me out one more time.
shot!
Think about it.
What condition are you using to get the data from your database?
What values are you provided to get that data?
Like I said, use print_r($_POST) and figure it out. ^_^
hey, thanks for all your help! I managed to figure it out up to a point where the correct records get selected and displayed.
panna
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lukelrc |
last post by:
Hi,
I have a dynamically created listbox. I'm trying to get one of the
options selected according to a passed value. This is what i have:
<select name="txtTheme" id="txtTheme">
...
|
by: Kris Rockwell |
last post by:
Hello (again),
I have gotten the dropdown list functionality to work through a few tricks
(probably not the most efficient, but it works) but I am not sure how to set
the default selected value....
|
by: Merdaad |
last post by:
My drop down list is populated from a static array in my codebehind (c#)
code.
I set the selected index based on some known values(from DB), when the
screen shows up, dropdown list shows that the...
|
by: Mike Wilson |
last post by:
Dear Group,
I have a heirarchical set of database tables, say - "order" and "order_type"
and want to display a series of orders in a grid control, and in place of
the order_type foreign key...
|
by: koti |
last post by:
hi
i have written some code for selecting an item in combobox dropdown
list which is in datagrid columm. by scrolling the mouse we select any
item from the list.
but by pressing the down key...
|
by: glenn |
last post by:
Hi folks,
If I want to select the first item in a DropDownList, I need to first select
any item other than the first item and then next I select the first item
which will then fire an event...
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
Greetings,
I have to load 30,000 unique names into a combox. Filling a dataTable takes
only a few milliseconds. But populating the combobox and displaying the list
takes several seconds - way...
|
by: Ronny Mandal |
last post by:
Hi!
I have an .aspx with some controls that are created dynamically. The
items are populated into the box by setting the DataSource-property to
a list. In addition I specify the text and value...
|
by: SunnySnow29 |
last post by:
Hi,
I have a 2 drop down lists in C# populated with data from a SQL 2005 db.
When a new item of data is inserted the second list must update to reflect the change (the first drop down list will...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |