jesse23 Posted January 26, 2007 Share Posted January 26, 2007 Hey everybody, this is my first post here and im excited because this looks like a great site. So im trying to implement a php code for my site that uses a drop down list. The purpose for the drop down is two do to things but i'll just focus on the one for now. The first is to put a zip code into this piece of html.[code]<!--Weather image provided by www.areacodehelp.com--><a href="http://www.areacodehelp.com/cgi-bin/weather/weather.cgi?pands=greeley, co" target="_blank"><img src="http://www.areacodehelp.com/cgi-bin/weather/weather.cgi?config=png&forecast=zone&alt=hwizone&pands=greeley, co&hwvbg=FFFFFF&hwvtc=B5OCOO&hwvusettf=0" alt="Zone Forecast for Greeley, CO" border="0" /></a> [/code]to do this i have this piece of php code. [code] <?php $dbHost = 'localhost'; // Database Host $dbUser = ''; // Database Username $dbPass = ''; // Database Password $dbName = ''; // Database Name $db = mysql_connect("$dbHost","$dbUser","$dbPass"); // Connect to the database. if (!$db) { die('Error : ' . mysql_error()); } // Database connection error checking. $select_db = mysql_select_db($dbName,$db); // Select database. if (!$select_db) { die('Error : ' . mysql_error()); } // More error checking. if(!isset($_POST['submit'])) { // If the form hasn't been submitted, display the form. ?> <form method="post" action="<?=$_SERVER['PHP_SELF'];?>"> <p><label for="weather">Select Your School: <br /> <?php $sql = "SELECT * FROM school ORDER BY City"; $result = mysql_query($sql); $dropdown = '<select name="weather">'; while ($row = mysql_fetch_assoc($result)) { $dropdown .= '<option value="'. $row['zip'] .'">' . $row['School'] . '</option>'; } $dropdown .= '</select>'; echo $dropdown; ?> </label> </p> <p><input type="submit" name="submit" value="Submit" /></p> </form> <?php } else { // If it has been submitted, process the form. $var = $_GET['weather']; // Get user choice from select box and assign variable. setcookie("Cookie[weather]", $var); // Put variable inside cookie. // echo the HTML with the variable inserted within the code. echo '<a href="http://www.areacodehelp.com/cgi-bin/weather/weather.cgi?pands=' .$var. '" target="_blank"><img src="http://www.areacodehelp.com/cgi-bin/weather/weather.cgi?config=png&forecast=zone&alt=hwizone&pands=' .$var. '&hwvbg=FFFFFF&hwvtc=B5OCOO&hwvusettf=0" alt="Zone Forecast for ' .$var. '" border="0" /></a>'; // you replace all instances of where the city or county would be in the code and replace it with the variable that contains the user inputted data. } ?>[/code]I have a test php page for my website to help get this up here[url=http://www.campusgoal.com/phptest2.php]http://www.campusgoal.com/phptest2.php[/url] Im trying to figure out why this script isnt working. I have my table set up like so in my phpmyadmin [table][tr][td]ID[/td] [td]School[/td] [td]zip[/td] [td]Address[/td] [td]Image[/td][/tr] [tr][td]1 [/td] [td]Customize Campusgoal to your School[/td] [td]0[/td] [td]0 [/td][td]0[/td][/tr] [tr][td]9[/td] [td]University of Northern Colorado, Greeley[/td] [td]80631 [/td] [td]www.unco.ed[/td] [td]unco.jpg[/td][/tr] [tr][td]8 [/td] [td]Colorado University, Boulder [/td] [td]80301[/td] [td]www.colorado.edu[/td] [td]cu.jpg[/td][/tr] [tr][td]10 [/td] [td]Colorado State University, Fort Collins[/td] [td]80521[/td] [td]www.colostate.edu [/td] [td]csu.jpg[/td][/tr][/table]Any help with this would be greatly appreciated. Thanks again.Jesse Quote Link to comment Share on other sites More sharing options...
Cep Posted January 26, 2007 Share Posted January 26, 2007 Your form has the post method set and your retrieving the get method.Change this line[code=php:0]<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">[/code]to this line[code=php:0]<form method="get" action="<?=$_SERVER['PHP_SELF'];?>">[/code] Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted January 26, 2007 Share Posted January 26, 2007 try using mysql_fetch_array[code] echo = '<select name="weather">'; while ($row = mysql_fetch_array($result)) { echo '<option value="'. $row['zip'] .'">' . $row['School'] . '</option>'; } echo '</select>';[/code] Quote Link to comment Share on other sites More sharing options...
jesse23 Posted January 28, 2007 Author Share Posted January 28, 2007 Thanks for helping me out with this. I am wondering what part of the code would i change to use the mysql_fetch_array Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 28, 2007 Share Posted January 28, 2007 <form method="post" action="<?=$_SERVER['PHP_SELF'];?>"> <p><label for="weather">Select Your School: <br /> <?php $sql = "SELECT * FROM school ORDER BY City"; $result = mysql_query($sql); $dropdown = '<select name="weather">'; while ($row = mysql_fetch_assoc($result)) <<<<<<<<<<<<<<<<< ? mysql_fetch_array { $dropdown .= '<option value="'. $row['zip'] .'">' . $row['School'] . '</option>'; } $dropdown .= '</select>'; echo $dropdown; ?> Quote Link to comment Share on other sites More sharing options...
jesse23 Posted January 29, 2007 Author Share Posted January 29, 2007 Ok so i have a script that i think will work but trying to get it working is a different story. I put the php code in and where i want my cookie to show up i get this message[quote]Warning: Cannot modify header information - headers already sent by (output started at /home/campusgo/public_html/phptest2.php:9) in /home/campusgo/public_html/phptest2.php on line 256Warning: Cannot modify header information - headers already sent by (output started at /home/campusgo/public_html/phptest2.php:9) in /home/campusgo/public_html/phptest2.php on line 257 [/quote]I am just wondering what does it mean cannot modify header? Quote Link to comment Share on other sites More sharing options...
Cep Posted January 29, 2007 Share Posted January 29, 2007 It means that your script has already sent header information or output and cannot send new or the same header information again. Please post your new script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.