MySQL dynamic drop down menu

Codes here !

Moderators: macek, egami, gesf

dkin
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Nov 29, 2002 2:25 am

MySQL dynamic drop down menu

Postby dkin » Fri Nov 29, 2002 2:30 am

Help, I am trying to write an html that will contain a php script that will read a data field from mysql and create a dynamic drop down menu (since the database updates all the time).

Unfortunately I can not succeed, how can I do it?



:cry:

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Fri Nov 29, 2002 2:52 am

can you show me a script and say what errors you get.

dkin
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Nov 29, 2002 2:25 am

Postby dkin » Fri Nov 29, 2002 4:06 am

Script:

<HTML>
<HEAD>
<TITLE>show car</TITLE>
</HEAD>
<BODY>
<FORM action="http://localhost/view.php" method="GET">

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'DVD';
$table = 'list';

$link = mysql_connect($host,$user,$pass);
if(!$link) die(mysql_error());
$select = mysql_select_db($db);
if(!$select) die(mysql_error());

$query = "SELECT name FROM list";
$result = mysql_query($query);
if(!$result) die(mysql_error());

print "search:<br>\n";
print "<select name=\"nam\">\n";
print "<option value=\"\"> </option>\n";
while($row = mysql_fetch_array($result))
{
print "<option value=\"$row[name]\">$row[name]</option>\n";
}
print "</select>\n";
mysql_connect(close);
?>

<input type="submit" value="submit">
</FORM>
</BODY>
</HTML>

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Fri Nov 29, 2002 4:54 am

I make a litlle corections, but i did not find any error.
Can you you te me what was wrongm what error you get ?

Code: Select all

<HTML>
<HEAD>
<TITLE>show car</TITLE>
</HEAD>
<BODY>
<FORM action="http://localhost/view.php" method="GET">

<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "DVD";
$table = "list";

$link = mysql_connect($host, $user, $pass);
if(!$link) die(mysql_error());
$select = mysql_select_db($db);
if(!$select) die(mysql_error());

$query = "SELECT name FROM list";
$result = mysql_query($query);
if(!$result) die(mysql_error());

echo "search:<br>\n";
echo "<select name=nam>\n";
echo "<option value=''> </option>\n";
while($row = mysql_fetch_array($result))
{
echo "<option value='$row[name]'>$row[name]</option>\n";
}
echo "</select>\n";
mysql_connect(close);
?>

<input type="submit" value="submit">
</FORM>
</BODY>
</HTML>

dkin
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Nov 29, 2002 2:25 am

Postby dkin » Fri Nov 29, 2002 6:48 am

Hi,

I tested the script and under SSEditor (PHP IDE - http://skyweb2k.com/sseditor/) I only changed the mysql_connect(close) to mysql_close($link).

In the IDE it works fine but under IE 6 I receive only the submit button and in Netscape I receive the following line \n" "\n"; mysql_close($link); ?> with a submit button and an empty drop down menu.

Any idea what is the problem, I use OmniHTTPD as a server and the PHP 4.2.3.

Thanks.
:(

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Fri Nov 29, 2002 6:57 am

i test your script under Apache . It is all ok.

Is it posibil to change server ?

dkin
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Nov 29, 2002 2:25 am

Postby dkin » Fri Nov 29, 2002 6:59 am

I will try in the weekend.

Thx.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 2 guests