Need help with a school assignment. Kind of urgent

Hey. Never used a forum for help before so I’m sorry if I have done something wrong. I was given an assignment in school to make a roster for a fictional Glee club. What I have done so far is not working and I cannot find why.

What is supposed to happen is it takes the mysql Query and shows the result as a table. Instead it prints out everything after line 19. where I open the table

Here is my code:
[php]

<?php /* Variables */ $role = $_POST['selectrole']; $email = $_POST['email']; $name = $_POST['name']; $age = $_POST['age']; $query = NULL; /* Connection to the database */ $server = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("students",$server); /* IF USER CHECKED OPTION 1 */ if(isset($_POST['formWheelchair']) && $_POST['formWheelchair'] == 'Yes') { $query = "SELECT * FROM glee WHERE clubrole = " . $role; echo ""; /* while loop selects all data in 'twittertable' and fetches rows while thier is still rows to fetch */ while ($row = mysql_fetch_array($query)) { echo ""; } echo "
" . $row['id'] . " " . $row['firstname'] . " " . $row['lastname'] . "
"; } mysql_close($server); ?>

[/php]

Do they teach you to use the mysql_ functions at school…? You should really use PDO or Mysqli, which replaced the mysql_* library 10 years ago…

Is the server set up to show all errors/warnings/notices? If not you should set that, either globally or directly in your script

[php]<?php
// start your scripts with this and you’ll see all errors
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

Download the sample PDO database in my signature. What you want is already done in current code. Do not use your obsolete code.

To answer the question, I don’t see where you’re executing the query.
[php]<?php
/* Variables */
$role = mysql_real_escape_string($_POST[‘selectrole’]);
$email = mysql_real_escape_string($_POST[‘email’]);
$name = mysql_real_escape_string($_POST[‘name’]);
$age = mysql_real_escape_string($_POST[‘age’]);

$query = NULL;
/* Connection to the database */
$server = mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“students”, $server);

/* IF USER CHECKED OPTION 1 */
if(isset($_POST[‘formWheelchair’]) && $_POST[‘formWheelchair’] == ‘Yes’) {
$res = “SELECT * FROM glee WHERE clubrole = ‘$role’”; // need quotes around strings
$query = mysql_query($res); // this is missing in your version

echo "<table>";
/* while loop selects all data in 'twittertable' and fetches rows while thier is still rows to fetch */ 
while ($row = mysql_fetch_array($query)) {
                    
     echo "<tr> <td>" . $row['id'] . "</td> <td>" . $row['firstname'] . "</td> <td>" . $row['lastname'] . "</td></tr>";
                     
}
echo "</table>";

}
mysql_close($server);
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service