mySQL and PHP help. Dropdown box not working.?

Ashlee

New member
I am at my wits end with this, so I thought I'd come here for some assistance. I'll give you all the information I can. I am creating a form that will add data to an SQL database. I have most of it done, the only thing is that the information that should be showing in a dropdown box isn't!! This is the page, where you can see the error:

http://www.dungeons.org.uk/slythpoints/addpoints.php

This is my PHP code, I can't work out what is wrong and how to get all those names to appear properly in the drop down box. When I do manage to get it in the box, the table isn't aligned and it just doesn't work!! If you can tell me what is wrong with my code, please do!!

-------------------------------------------------------------------------------------
<html>
<head>
<title>Slytherin Activity Point</title>
<link href='sap.css' rel='stylesheet' type='text/css'>
</head>
<body>

<?php


include ("dbconnect2.php");

$query = "SELECT * FROM ibf_members"
. " ORDER BY name";
$results = mysql_query($query);

//echo $query;

$num = mysql_numrows($results);

echo "<br /><br />";
echo "<center>";
echo "<form action='addpoints.php' method='POST'>";
echo "<table width=50%>";
echo "<tr>";
echo "<td><b>Student Name:</b><td><select name='p_to'></td>";

$i = 0;

echo "<option selected value=0>--CHOOSE A STUDENT--</option>";

while ($i < $num) {

$membernumber = mysql_result($results, $i, "id");
$membername = mysql_result($results, $i, "name");
//echo "<i>$membernumber</i> <b>$membername</b> <br />";

echo "<option value=$membernumber>$membername</option>";

$i++;
}
echo "</tr>";
echo "</select>";

echo "<tr>";
echo "<td><b>Staff ID:</b></td><td><input type=text name=staff_id></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Points:</b></td><td><input type=text name=point_submitted></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Reason:</b></td><td><input type=text name=reason></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Month Submitted:</b></td><td><input type=text name=month></td>";
echo "</tr>";

echo "<input type=hidden name=flag value=1>";
echo "<tr>";
echo "<td>&nbsp</td><td><input type=submit value='Add Points!'></td>";
echo "</tr>";
echo "</table>";

echo "</form>";
echo "</center>";

$memberid = $_POST['member_id'];
$staffname = $_POST['staff_id'];
$point = $_POST['point_submitted'];
$reason = $_POST['reason'];
$month = $_POST['month'];

//echo "$point $memberid $staffname $reason $month";

if (isset($_POST['flag']))
{
if ($memberid == '')
{
$message = "Please select a student!!";
echo "<font color=#FF0000>Points were not added: $message</font>";
}
else
{

include ("dbconnect1.php");

$sql = "INSERT INTO `points` (`member_id`,`staff_id`,`point_submitted`,`reason`,`month`)"
."VALUES ('$memberid','$staffname','$point','$reason','$month')";

mysql_query($sql,$db);

echo "<font color=#347235>Points added!</font>";

mysql_close();
}

}

echo "</center>";

?>

</body>
</html>
-------------------------------------------------------------------------------------

THANKS!
 
Back
Top