student table..
csci01members..
i will put the student record in the csci01members, my code doesn't have a syntax error..
but it always get's stuck in "The user is already a member".. EVEN if he's not..
i already got the code of adding the record..
but i need an error trapping so that if the user is
already in the csci01members table.. it can't add the record or
he cannot view the members of csci01 so that the member already will not be seen
in the list of adding into table...
please help again......
- Code: Select all
<?php
$errors="";
if(isset($_GET['add']))
{
$con = mysql_connect("localhost","root","");
if(!$con)
{ die("could not connect to server".mysql_error()); }
mysql_select_db("login", $con);
if (empty($errors)){
$check = mysql_query("SELECT * from csci01members");
$check_count = mysql_num_rows($check);
if ($check_count == 1) {
die (" The user is already a member.");
}
}
$result = mysql_query("SELECT * from students where username='$_GET[add]'");
$result_count = mysql_num_rows($result);
if ($result_count == 0) {
echo "<font color=red><br /> The user doesn't exists.</font>";
}
else
{
while($row = mysql_fetch_array($result))
{
echo "Student Number: $row[username]<br>Name: $row[namelast]
, $row[namefirst]<br><br> was added to the group<br><br>";
$sn = $row['username'];
$nl = $row['namelast'];
$nf = $row['namefirst'];
$nm = $row['namemi'];
mysql_query("INSERT INTO csci01members (username, namelast, namefirst, namemi)
VALUES ('$sn', '$nl', '$nf', '$nm')");
mysql_close($con);
}
}
}
$con = mysql_connect("localhost","root","");
if(!$con)
{ die("could not connect to server".mysql_error());}
mysql_select_db("login", $con);
$sql="Select * from students";
$sql_result=mysql_query($sql)
or exit("Sql Error".mysql_error());
$sql_num=mysql_num_rows($sql_result);
if($row = mysql_num_rows($sql_result) == 0)
{
echo "There are no registered student yet<br><br>";
$name=$row["username"];
$class=$row["namelast"] .$row["namefirst"];
$accept = "<a href='?add=$row[username]'> </a>";
}
else
{
echo "<table border = 0 width=\"200%\">";
echo "<tr>";
echo "<td width = '20%' > <b><center>USN</center></b></td>
<td width = '60%'><b><center>Name</center></b></td>
<td width = '10%'><b><center>Action</center></b></td>";
echo "</tr>";
while($sql_row=mysql_fetch_array($sql_result))
{
$name=$sql_row["username"];
$class=$sql_row["namelast"] . ', '.$sql_row["namefirst"];
$accept = "<a href='?add=$sql_row[username]'>[Add]</a>";
echo "<td >".$name."</td>";
echo "<td>".$class."</td>";
echo "<td>".$accept."</td></tr>";
}
}
echo "</table>";
mysql_close();
?>


