PHP/HTML Query from Dropdown menu -
below create tables, html file has drop down menu has artists, , php file based on artist displays title's of albums artist.
i can't seem php file work. can value drop down menu, don't think can values database using value.
connects database
<?php // connect.php // include file providing function connect mysql database // include file on every page needs connect db. // usage: // include('connect.php'); // declare connection function function dbconnect ($name, $pw) { // create mysql connection $connection = mysql_connect("localhost", $name, $pw); // select correct database mysql_select_db("usr_".$name."_1", $connection); } // call connect function // first argument user name // second argument password dbconnect('yourusername', 'yourpassword'); ?> tables
create table cd ( cdnum int not null, title varchar(40), artist varchar(40), category varchar(20), price numeric(6,2) ) engine = innodb; create table customer ( cnum int not null, cname varchar(25), ccity varchar(25) ) engine = innodb; create table buys ( cnum int not null, cdnum int not null, qty int not null ) engine = innodb; html file has drop down menu.
<html> <head> <title> listartist </title> <meta name="author" content=""> </head> <body> <h1>find artist's albums page</h1> dropdown list of artists, user should able pick artist , see list of albums (all fields in cd table) artist. <hr> <form action="listartist.php" method="post"/> artist: <select name="mydropdown"> <option value="pink floyd">pink floyd</option> <option value="pearl jam">pearl jam</option> <option value="shania twain">shania twain</option> <option value="gwen stefani">gwen stefani</option> <option value="vince gill">vince gill</option> <option value="dixie chicks">dixie chicks</option> </select> <br> <br> <input type="submit" value="list artist"/> </form> </body> </html> php file suppose take artist user , display title's of albums.
<html> <head> <title>listartist.php</title> </head> <body> <h1>printschedule form action php page </h1> <p> <?php // include files: // connection function include('connect.php'); $dd = $_post['mydropdown']; // used fixed-width font echo "<pre>\n"; // print id (name) echo "albums of artist: $dd\n"; // set format string $fmt = "%40s\n"; // print header line printf($fmt, "album name"); // person likes $r1 = mysql_query("select title cd artist = '$dd'"); echo($r1[0]); // loop on courses, printing each 1 while ($r = mysql_fetch_row($r1)) { printf($fmt,$r[0]); echo($r[0]); } // free result set mysql_free_result($r1); echo "</pre>\n"; ?> </body> </html>
Comments
Post a Comment