Jump to content

[SOLVED] Can't find the problem (no error message)!


Jakebert

Recommended Posts

OK, here's the deal. This code is really weirdly formatted (sorry!) and hard to understand, so I'm going to try and make it as easy as possible. Here's a breakdown of what the user should do:

 

1. The user sees a list of his classes (stored in the classes table in the DB). He picks one.

$instructor = $_COOKIE['USERNAME'];
  $query = ("SELECT * FROM classes WHERE instructor='$instructor'");
  
  $sql = mysql_query($query) or die(mysql_error());
  
  echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
  <table border="1" cellspacing="2" cellpadding="3">';
  while ($row = mysql_fetch_array($sql))
  {
  	
  	echo '<tr><td>';
  	echo $row['id'];
  	echo '</td><td>';
  	echo $row['session'];
  	echo '</td><td>';
  	echo $row['day'];
  	echo '</td><td>';
  	echo $row['time'];
  	echo '</td><td>';
  	echo $row['level'];
  	echo '</td><td>';
  	
  	$class_id = $row['id'];
  	
  	echo '<input type = "hidden" name = "class_id" value = "'.$class_id.'" />';
  	echo '<input type = "submit" name = "pickclass" value = "Run" /></form>';
  echo '</td></tr>'; 	
  	}
  	
  	echo '</table>';

 

2. The user is shown a list of the students in that class. He picks one.

	if (isset($_POST['pickclass'])) {



   echo '<table>';
      
$class_id = $_POST['class_id'];

echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';

echo '<tr><td><strong>Instructor: </td></tr></table>';



echo $_COOKIE['USERNAME'];

$instructor = $_COOKIE['USERNAME'];


echo '<table border="1" cellspacing="2" cellpadding="3">';


echo '<tr><td>ID</td><td>First</td><td>Last</td><td>Gender</td><td>Level</td></tr>';

$query = ("SELECT * FROM `students` WHERE classid='$class_id' LIMIT 0, 30");
  
  $sql = mysql_query($query) or die(mysql_error());
  

while ($row = mysql_fetch_array($sql)) {

echo '<tr><td>';
echo $row['id'];
echo '</td><td>';
echo $row['fname'];
echo '</td><td>';
echo $row['lname'];
echo '</td><td>';
echo $row['gender'];
echo '</td><td>';
echo $row['level'];
echo '</td><td>';

echo '<input type = "hidden" name = "id" value = "'.$row['id'].'" />';
echo '<input type = "hidden" name = "fname" value = "'.$row['fname'].'" />';
echo '<input type = "hidden" name = "lname" value = "'.$row['lname'].'" />';
echo '<input type = "hidden" name = "gender" value = "'.$row['gender'].'" />';
echo '<input type = "hidden" name = "level" value = "'.$row['level'].'" />';
echo '<input type = "submit" name = "submit" value = "GO!" /></td></tr></table></form>';

 

Here's the problem: the only thing showing up under step two is the table headers (i.e. First, Last, etc.)

I don't know why. I feel like it's a tiny problem but I can't find it! Help!

 

----

 

In reality, the code looks like this. Don't hurt me!

//something else comes before this
else

{
if (isset($_POST['pickclass'])) {



   echo '<table>';
      
$class_id = $_POST['class_id'];

echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';

echo '<tr><td><strong>Instructor: </td></tr></table>';



echo $_COOKIE['USERNAME'];

$instructor = $_COOKIE['USERNAME'];


echo '<table border="1" cellspacing="2" cellpadding="3">';


echo '<tr><td>ID</td><td>First</td><td>Last</td><td>Gender</td><td>Level</td></tr>';

$query = ("SELECT * FROM `students` WHERE classid='$class_id' LIMIT 0, 30");
  
  $sql = mysql_query($query) or die(mysql_error());
  

while ($row = mysql_fetch_array($sql)) {

echo '<tr><td>';
echo $row['id'];
echo '</td><td>';
echo $row['fname'];
echo '</td><td>';
echo $row['lname'];
echo '</td><td>';
echo $row['gender'];
echo '</td><td>';
echo $row['level'];
echo '</td><td>';

echo '<input type = "hidden" name = "id" value = "'.$row['id'].'" />';
echo '<input type = "hidden" name = "fname" value = "'.$row['fname'].'" />';
echo '<input type = "hidden" name = "lname" value = "'.$row['lname'].'" />';
echo '<input type = "hidden" name = "gender" value = "'.$row['gender'].'" />';
echo '<input type = "hidden" name = "level" value = "'.$row['level'].'" />';
echo '<input type = "submit" name = "submit" value = "GO!" /></td></tr></table></form>';


}
}	
else
{
	echo $_COOKIE['USERNAME'];

$instructor = $_COOKIE['USERNAME'];
  $query = ("SELECT * FROM classes WHERE instructor='$instructor'");
  
  $sql = mysql_query($query) or die(mysql_error());
  
  echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
  <table border="1" cellspacing="2" cellpadding="3">';
  while ($row = mysql_fetch_array($sql))
  {
  	
  	echo '<tr><td>';
  	echo $row['id'];
  	echo '</td><td>';
  	echo $row['session'];
  	echo '</td><td>';
  	echo $row['day'];
  	echo '</td><td>';
  	echo $row['time'];
  	echo '</td><td>';
  	echo $row['level'];
  	echo '</td><td>';
  	
  	$class_id = $row['id'];
  	
  	echo '<input type = "hidden" name = "class_id" value = "'.$class_id.'" />';
  	echo '<input type = "submit" name = "pickclass" value = "Run" /></form>';
  echo '</td></tr>'; 	
  	}
  	
  	echo '</table>';

}
}

Link to comment
Share on other sites

Start by debugging the first form (the code at the end of what you posted.) Do a "view source" in your browser and check if it is producing what you expect. It appears that you are putting one opening <form ...> tag before the while() loop, then putting repeated section with a hidden field for the class_id, the submit button, and a closing </form> tag. You would need to use different names for each hidden class_id field (with the same name, only the last value in the <form></form> will be used) and if you actually intend to make each table row its' own form, you would need to get the opening and closing <form></form> tags matched up. If you intended that there be a single form, then you would need to put a single closing </form> tag after the end of the while() loop.

 

Short-answer: Start at the first step and make sure it is doing what you expect and submitting the data you expect, then go onto the next step that uses the data from the first step.

Link to comment
Share on other sites

Woohoo! That worked. New problem now though, but instead of making another thread called "No error message" I thought I'd just use this one. Same deal, only table headers are appearing. Not sure what the issue is.

$date = date("m");
if (($date == 09) || ($date == 10) || ($date = 11))
{$session = "Fall";}

if (($date == 12) || ($date == 01) || ($date == 02) || ($date == 03))
{$session = "Winter";}

if (($date == 04) || ($date == 05) || ($date == 06))
{$session = "Spring";}

if (($date == 07) || ($date == 08))
{$session = "Summer";}
echo $date;
echo $session;

$username = $_COOKIE['USERNAME'];

echo '<table border = "2"><tr> <td><b>Monday</b></td> <td><b>Tuesday</b></td> <td><b>Wednesday</b></td> <td><b>Thursday</b></td> <td><b>Friday</b></td> <td><b>Saturday</b></td> <td><b>Sunday</b></td> </tr><tr>';


$query = ("SELECT * FROM classes WHERE session = '$session' AND day = 'Monday'") ;

$sql = mysql($query) or die(mysql_error());
echo '<td>';


if (mysql_num_rows($sql) == 0) {

echo 'No Classes';

}

else
{

while ($row = mysql_fetch_array($sql))

{

echo $row['time'];
echo $row['level'];
echo '<br />';
}
}

$query = ("SELECT * FROM classes WHERE session = '$session' AND day = 'Tuesday'") ;

$sql = mysql($query) or die(mysql_error());
echo '</td><td>';
if (mysql_num_rows($sql) == 0) {

echo 'No Classes';

}

else
{

while ($row = mysql_fetch_array($sql))

{

echo $row['time'];
echo $row['level'];
echo '<br />';
}
}
$query = ("SELECT * FROM classes WHERE session = '$session' AND day = 'Wednesday'") ;

$sql = mysql($query) or die(mysql_error());

while ($row = mysql_fetch_array($sql))

{
echo '<td>';
echo $row['time'];
echo $row['level'];
echo '<br /></td>';
}

$query = ("SELECT * FROM classes WHERE session = '$session' AND day = 'Thursday'") ;

$sql = mysql($query) or die(mysql_error());

if (mysql_num_rows($sql) == 0) {

echo 'No Classes';

}

else
{

while ($row = mysql_fetch_array($sql))

{

echo $row['time'];
echo $row['level'];
echo '<br />';
}
}
$query = ("SELECT * FROM classes WHERE session = '$session' AND day = 'Friday'") ;

$sql = mysql($query) or die(mysql_error());
echo '</td><td>';
while ($row = mysql_fetch_array($sql))

{

echo $row['time'];
echo $row['level'];
echo '<br />';
}

$query = ("SELECT * FROM classes WHERE session = '$session' AND day = 'Saturday'") ;

$sql = mysql($query) or die(mysql_error());
echo '</td><td>';
if (mysql_num_rows($sql) == 0) {

echo 'No Classes';

}

else
{

while ($row = mysql_fetch_array($sql))

{

echo $row['time'];
echo $row['level'];
echo '<br />';
}
}
echo '</td><td>';

$query = ("SELECT * FROM classes WHERE `session` = 'Fall' AND `day` = 'Sunday' LIMIT 0, 30 ") ;

$sql = mysql($query) or die(mysql_error());
echo '</td><td>';
while ($row = mysql_fetch_array($sql))

{

echo $row['time'];
echo $row['level'];
echo '<br />';
}

echo '</td></tr>';
?>

Link to comment
Share on other sites

For debugging, I would recommend echoing your $query variables to see exactly what is in them.

 

The only apparent problem is that leading zeros on numbers in php make them octal values, so it is likely your $date tests are not producing the results you expect. I would put some quotes around the values on the right-side of the == comparisons so that what is in $date will match them.

Link to comment
Share on other sites

Hmmm...tried that, doesn't seem to be working. the $date variable is working out fine.

 

Here's what happens when I echo my $query variable:

 

SELECT * FROM classes WHERE session = 'Fall' AND day = 'Monday'

 

AHA, That's the only one that echoes, so maybe there's an issue with the {}? Did I forget one? Can't seem to find the problem. :wtf:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.