dub_stylee Posted December 7, 2008 Share Posted December 7, 2008 Hello all, I am new to the site. I have tried searching the forums before creating this posting, to no avail. Sorry if this has been asked/answered before. I am trying to use PHP to generate a selection list based on the results of a MySQL query. I have had similar problems trying to use published examples, so I am thinking that it may be a configuration problem on my web server? Anyway, here is the garbage output that I am receiving when trying to view my page (some info will be omitted for privacy): "; echo ""; echo ""; $host = "******"; $port = "****"; $user = "guest"; $pass = "guest"; $dbname = "stores7"; $conn = mysql_connect("$server", "$user", "$pass") or die("MySQL Connection Error"); $db = mysql_select_db($dbname) or die("Missing Database"); $query = "SELECT manu_name FROM manufact"; echo "$query"; echo $query; $result = mysql_query($query) or die("Invalid Query"); echo "$result"; echo $result; /* create the selection list */ echo " \n"; echo " \n"; echo ""; echo ""; ?> And of course, the .html file: <?php /* Filename: index.html * Description: home page */ echo "<html>"; echo "<head><title>myTunes Database</title></head>"; echo "<body>"; $host = "*****"; $port = "****"; $user = "guest"; $pass = "guest"; $dbname = "stores7"; $conn = mysql_connect("$server", "$user", "$pass") or die("MySQL Connection Error"); $db = mysql_select_db($dbname) or die("Missing Database"); $query = "SELECT manu_name FROM manufact"; echo "$query"; echo $query; $result = mysql_query($query) or die("Invalid Query"); echo "$result"; echo $result; /* create the selection list */ echo "<form action = 'processform.php' method = 'POST'> <select name = '$manu_name'>\n"; while ($row = mysql_fetch_array($result)) { extract($row); echo "<option value='$manu_name'>$manu_name</option>\n"; } echo "</select>\n"; echo "<input type = 'submit' value = 'Select Manufacturer'> </form>\n"; echo "</body>"; echo "</html>"; ?> Thanks very much in advance! Brian ??? Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/ Share on other sites More sharing options...
MadTechie Posted December 7, 2008 Share Posted December 7, 2008 Humm.. is this a php file (end with .php) also echo "<form action = 'processform.php' method = 'POST'> <select name = '$manu_name'>\n"; should probably be echo "<form action = 'processform.php' method = 'POST'> <select name = 'manu_name'>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/#findComment-708194 Share on other sites More sharing options...
genericnumber1 Posted December 7, 2008 Share Posted December 7, 2008 Your php doesn't seem to be working. Try the simple file: <?php echo "Hello World!": ?> and then view-source. If you see anything other than "Hello World!" your php definitely isn't working properly. If you view-source on this page you've posted here does it look exactly like your script? Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/#findComment-708196 Share on other sites More sharing options...
kenrbnsn Posted December 7, 2008 Share Posted December 7, 2008 PHP code should be files with the extension ".php", not ".html", unless you've modified your web server to serve .html files to php. Ken Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/#findComment-708197 Share on other sites More sharing options...
dub_stylee Posted December 7, 2008 Author Share Posted December 7, 2008 I tried the simple Hello world! example, and it displays nothing on the page. View source reveals the original <?php echo "Hello world!"; ?> ... Brian Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/#findComment-708198 Share on other sites More sharing options...
genericnumber1 Posted December 7, 2008 Share Posted December 7, 2008 And as they said: are you using a .php extension for the file? Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/#findComment-708200 Share on other sites More sharing options...
dub_stylee Posted December 7, 2008 Author Share Posted December 7, 2008 Okay, renaming the file to .php did the trick! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/135858-solved-php-producing-garbage-output/#findComment-708202 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.