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:
[code=php]$sql3="SELECT ID, UploadDate FROM Telkom";
$result2=mysql_ query($sql3);
$options="";
while ($row=mysql_fet ch_array($resul t2)) {
$id=$row["ID"];
$date=$row["UploadDate "];
$options.="<OPT ION VALUE=\"$id\">" .$date;
The code for the actual dropdown menu is as follows:
<form name="selectdat a" action="select_ telkom_data.php " method="post">
<SELECT NAME="thedate">
<OPTION>Choos e
<?=$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_d ata.php looks like this:
<?php
include "admin/dataw.php";
include("global .inc.php");
$sysadminemail = "webmaster@dtms i.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='$da te' ";
$result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
$num_rows = mysql_num_rows( $result);
$row = mysql_fetch_arr ay($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>Sor ry - no records exist. ";
}
else {
include("show_t elkom_data.php" );
mysql_close($li nk);
}
}
?>[/code]
[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
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:
[code=php]$sql3="SELECT ID, UploadDate FROM Telkom";
$result2=mysql_ query($sql3);
$options="";
while ($row=mysql_fet ch_array($resul t2)) {
$id=$row["ID"];
$date=$row["UploadDate "];
$options.="<OPT ION VALUE=\"$id\">" .$date;
The code for the actual dropdown menu is as follows:
<form name="selectdat a" action="select_ telkom_data.php " method="post">
<SELECT NAME="thedate">
<OPTION>Choos e
<?=$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_d ata.php looks like this:
<?php
include "admin/dataw.php";
include("global .inc.php");
$sysadminemail = "webmaster@dtms i.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='$da te' ";
$result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
$num_rows = mysql_num_rows( $result);
$row = mysql_fetch_arr ay($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>Sor ry - no records exist. ";
}
else {
include("show_t elkom_data.php" );
mysql_close($li nk);
}
}
?>[/code]
[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
Comment