homepage Welcome to WebmasterWorld Guest from 54.197.171.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Trouble with Pulldown Menu
Spiceydog




msg:3645913
 5:00 pm on May 9, 2008 (gmt 0)

I have a pulldown menu that is being made to correspond with a MySQL database through PHP. It should be very simple but for some reason the HTML I am using for the structure of the pulldown menu is just disappearing on the web page. The HTML is between two different <?php ?> things. Here is the entire script with --> pointing towards the HTML that is disappearing:

<?php
if(isset($_POST['btnSign']))
{
include 'login.php';

$name = trim($_POST['name']);
$adviser = trim($_POST['adviser']) OR DIE ("MESSAGE!");
$year = trim($_POST['year']);
$first = trim($_POST['first']);
$second = trim($_POST['second']);
$third = trim($_POST['third']);
$fourth = trim($_POST['fourth']);
$fifth = trim($_POST['fifth']);
$sixth = trim($_POST['sixth']);
$seventh = trim($_POST['seventh']);
$eighth = trim($_POST['eighth']);

{
$query = "INSERT INTO schedule(name,
year,
adviser,
first,
second,
third,
fourth,
fifth,
sixth,
seventh,
eighth)
VALUES ('$name',
'$year',
'$adviser',
'$first',
'$second',
'$third',
'$fourth',
'$fifth',
'$sixth',
'$seventh',
'$eighth')";
}
{
mysql_query($query) or die('YOUR FIELD WAS TO LONG!');

header('Location: schedule.php');
exit;
} }
?>
<html>
<head>
<title>Make Your Own Schedule</title>
<link href="schedule.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="right">
<br><br><br><h3><div class="titlez3"><center>Search by Name: <form method="post" action="output.php"><input type="text" name="searchname" size="30"><input type="submit" value="GO"></form></center></div></h3>
<h3><div class="titlez4"><center>Search by Class: <br /><form method="post" action="searchclass.php"><input type="text" name="searchclass" size="30"><input type="submit" value="GO"></center></div></h3>
<h3><div class="titlez5"><center>Search by Year at CFS: <br /><input name="searchclassmen" type="text" size="30" maxlength="50"></center></div></h3>
</div>
<div class="left">
<h1><div class="titlez2"><center>Make a New Schedule:</center></div></h1>
<form method="post" name="schedule" action="schedule.php">
<div class="labelz">Name:</div>
<div class="fieldz">
<input name="name" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Year at CFS:</div>
<div class="fieldz">
<input type="radio" name="year" value="Freshmen">Freshmen
<input type="radio" name="year" value="Sophomore">Sophomore
<input type="radio" name="year" value="Junior">Junior
<input type="radio" name="year" value="Senior">Senior
</div>
<div class="labelz">Adviser:</div>
<div class="fieldz">
<select name="adviser">
<option value="null" selected>--Select Your Adviser--</option>
<option value="Dave Worden">Dave Worden</option>
<option value="Rob LaVelle">Rob LaVelle</option>
<option value="Ken Mitchell">Ken Mitchell</option>
<option value="Frances Brindle">Frances Brindle</option>
<option value="Jamie Hysjulien">Jamie Hysjulien</option>
<option value="Bryce Little">Bryce Little</option>
<option value="Willy Rotella">Willy Rotella</option>
<option value="Elise London">Elise London</option>
<option value="Jon Lepofsky">Jon Lepofsky</option>
<option value="Susan Kincaid & Tim O'Hara">Susan Kincaid & Tim O'Hara</option>
<option value="Guillermo Parra">Guillermo Parra</option>
<option value="Amelia Shull">Amelia Shull</option>
<option value="Carrie Huff">Carrie Huff</option>
</select>
</DIV>
<?php
include 'login.php';
$query = "SELECT class
FROM classes
WHERE period='1'";
$result = mysql_query($query) or die("Couldn't execute query.");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
--><div class="labelz">First Period:</div>
--><div class="fieldz">
--><select name="first">
--><option value="null" selected>Select Your Adviser</option>
--><option value="<?php print " {$row['class']} ";?>"><?php print " -->{$row['class']} "; ?></option></select>
--></div>
<?php
}
?>
<div class="labelz">Second Period:</div>
<div class="fieldz">
<input name="second" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Third Period:</div>
<div class="fieldz">
<input name="third" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Fourth Period:</div>
<div class="fieldz">
<input name="fourth" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Fifth Period:</div>
<div class="fieldz">
<input name="fifth" type="text" size="50" maxlength="50">
</div>
<div class="labelz">Sixth Period:</div>
<div class="fieldz">
<input name="sixth" type="text" size="50" maxlength="30">
</div>
<div class="labelz">Seventh Period:</div>
<div class="fieldz">
<input name="seventh" type="text" size="50" maxlength="30">
</div>
<div class="labelz">Eighth Period:</div>
<div class="fieldz">
<input name="eighth" type="text" size="50" maxlength="30">
</div>
<div class="titlez1"><center><input name="btnSign" type="submit" value="Make Schedule"></center></div></form></div>
</body>
</html>

 

jezra




msg:3645924
 5:10 pm on May 9, 2008 (gmt 0)

You may not be getting any results from your database.
after your query:
$result = mysql_query($query) or die("Couldn't execute query.");

check the number of results in the $result object using
mysql_num_rows($request);

jatar_k




msg:3646677
 1:44 pm on May 10, 2008 (gmt 0)

also, instead of putting this

$result = mysql_query($query) or die("Couldn't execute query.");

which doesn't tell you why the query died

use this
$result = mysql_query($query) or die("Couldn't execute query: " . mysql_error());

this will return the error from mysql and help you find the problem

Spiceydog




msg:3646778
 4:45 pm on May 10, 2008 (gmt 0)

Oh! Alright the problem was that I didn't have anything in the table "classes".... ugh...

[edited by: Spiceydog at 4:46 pm (utc) on May 10, 2008]

[edited by: coopster at 1:31 am (utc) on May 15, 2008]
[edit reason] general [/edit]

jatar_k




msg:3646785
 4:51 pm on May 10, 2008 (gmt 0)

hehe

happens to all of us, glad you found it :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved