Problem with passing variable using pull down manu in PHP

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 with passing variable using pull down manu in PHP

Post by szms »

Hello Every one!!

I am 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:

Code: Select all

<?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) 
&#123; 
print "There are currently $num_rows Domain in the Database <p>"; 
print "<table border = 1>\n"; 
while($a_row = mysql_fetch_row($result)) 
&#123; 
print "<tr>\n"; 
foreach ($a_row as $field) 
print "\t<td>$field</td>\n"; 
$Domain_Name&#1111;] = $field; 
print "</tr>\n"; 
&#125; 
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 &#125; 
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

Code: Select all

<? 
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&#1111;'DomainMenu'] == $Existing_Domain) 
$result = mysql_query("SELECT Description FROM Domain where Name = '$Existing_Domain'"); 
$num_rows = mysql_num_rows($result); 
if ($num_rows > 0) 
&#123; 
$Domain_Description = mysql_result($result, 0, 'Description'); 
print "<h1> $Existing_Domain Description </h1>\n"; 
print "$Domain_Description"; 
&#125; 
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.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Where, in ShowDomainDescription1.php, is $Existing_Domain set? It might be comparing "" to "", if both $Existing_Domain and $_POST['DomainMenu'] aren't being set properly.

Also, you have a space in the first snippet, at

Code: Select all

<?php
foreach ($Domain_Name as $Existing_Domain)
print " <option value="$Existing_Domain ">$Existing_Domain</option>";
?>
You probably don't want that space in <option value=\"$Existing_Domain \">
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Moved to PHP - Normal.

Mac
Post Reply