Problem is passing value through pull down menu to a destina

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Problem is passing value through pull down menu to a destina

Post by szms »

Hello Every one!!

I am a beginner of PHP and having problem with passing value through a pull down menu and then using that value in a PHP vile to execute a query using mysql.

Here is my code of HTML pull down menu:

<?php
require("");
$link = mysql_connect($host,$user,$pass);
if (!$link)
die("Couldn't connect to MySQL");

mysql_select_db($db)
or die("Couldn't open $db: ".mysql_error());


$result = mysql_query("SELECT Name FROM Domain");
$num_rows = mysql_num_rows($result);
if ($num_rows)
{
print "There are currently $num_rows Domain in the Database <p>";
print "<table border = 1>\n";
while($a_row = mysql_fetch_row($result))
{
print "<tr>\n";
foreach ($a_row as $field)
print "\t<td>$field</td>\n";
$Domain_Name[] = $field;
print "</tr>\n";
}
print "</table>\n";
?>


<form action = "ShowDomainDescription1.php" Method = "POST">

Select any of the domain for more information<br>

<select name = "DomainMenu">
<?php
foreach ($Domain_Name as $Existing_Domain)
print " <option value=\"$Existing_Domain \">$Existing_Domain</option>";
?>
</select>
<input type = "submit" value = "Show" >

</form>

<?php }
else
print "There is no data available in the database";
mysql_close($link); ?>


I am getting foloowing worning
Warning: Supplied argument is not a valid MySQL result resource in /home/public_html/ShowDomainDescription1.php on line 12
There is no Domain called , Please check the Domain list again.


Here is my code for ShowDomainDescription1.php


<?
require("");
$link = mysql_connect($host,$user,$pass);
if (!$link)
die("Couldn't connect to MySQL");

mysql_select_db($db)
or die("Couldn't open $db: ".mysql_error());

if($_POST['DomainMenu'] == $Existing_Domain)
$result = mysql_query("SELECT Description FROM Domain where Name = '$Existing_Domain'");
$num_rows = mysql_num_rows($result);
if ($num_rows)
{
$Domain_Description = mysql_result($result, 0, 'Description');
print "<h1> $Existing_Domain Description </h1>\n";
print "$Domain_Description";
}
else
print "There is no Domain called $Existing_Domain, Please check the Domain list again.";
mysql_close($link);

?>


It would be great if any one help me to solve this problem.


?>
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

hi,

It never reaches this the <h1> $Existing_Domain Description </h1> bit cos the if statement is not testing anything hence why it is jumping to the else statement and you were recieving the warning.

try this:

Code: Select all

//the line below is line 12 and it was not testing anything so > 0 was added
if ($num_rows > 0) 
{ 
$Domain_Description = mysql_result($result, 0, 'Description'); 
print "<h1> $Existing_Domain Description </h1>\n"; 
print "$Domain_Description"; 
} 
else 
print "There is no Domain called $Existing_Domain, Please check the Domain list again."; 
mysql_close($link);
let me know how you get on I cant test code from where I am.
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Still not working

Post by szms »

Thank you for your reply. I tried to follow your direction but still did not work. Now I am getting the following warning.

Warning: Supplied argument is not a valid MySQL result resource in /home/public_html/ShowDomainDescription1.php on line 12
There is no Domain called , Please check the Domain list again.



Could you plese take a look of the following code for ShowDomainDescription1.php and specially for the highlighted lines. Thank you.


<?
require("");
$link = mysql_connect($host,$user,$pass);
if (!$link)
die("Couldn't connect to MySQL");
mysql_select_db($db)
or die("Couldn't open $db: ".mysql_error());


if($_REQUEST['DomainMenu'] == $Existing_Domain)
$result = mysql_query("SELECT Description FROM Domain where Name = '$Existing_Domain'");

$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{
$Domain_Description = mysql_result($result, 0, 'Description');
print "<h1> $Existing_Domain Description </h1>\n";
print "$Domain_Description";
}
else
print "There is no Domain called $Existing_Domain, Please check the Domain list again.";
mysql_close($link);

?>
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

I think this a database problem, check the capitilization, if that fails, post a dump of your database, maybe then someone can help you.

Cheers!
Post Reply