Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

problem with passing variables through a pull down menu

General discussions related to php

Moderators: macek, egami, gesf

problem with passing variables through a pull down menu

Postby szms » Thu Jun 26, 2003 5:39 pm

Hello Every one!!

I am having problem with passing value through a pull down menu and then using that value in a PHP while to execute a query using mysql. So it would be great if you take a look of my code and give me some suggestion. Thank you.

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)
{
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 following 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['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);

?>
szms
New php-forum User
New php-forum User
 
Posts: 10
Joined: Thu Jun 26, 2003 7:42 am

Re: problem with passing variables through a pull down menu

Postby WiZARD » Thu Jun 26, 2003 11:40 pm

check youre database carefuly
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.