Jump to content

i cant check if the user is already registered..


vinsux

Recommended Posts

i have two tables..

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......

 

 

 

   
	<?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();
				?>

Are you aware of what this script is doing? Specifically, this part here

 

			$check = mysql_query("SELECT * from csci01members");

		$check_count = mysql_num_rows($check);	
		if ($check_count == 1) {
			 die ("  The user is already a member.");
			}
		}

		$check = mysql_query("SELECT * from csci01members");

		$check_count = mysql_num_rows($check);	
		if ($check_count == 1) {
			 die ("  The user is already a member.");
			}

 

You are selecting everything from the table. There should be a WHERE clause to see if the username is already there and then if the search returns no matches you can proceed to add the member. Assuming you've got 1 member in the table, that script will always end up there.

tnx for the info...

 

 

 

i already debug it..

 

i just put  a where clause in this statement..

 

$check = mysql_query("SELECT * from csci01members");

 

 

thank you very much....

 

this site is great in helping newbies in php...

 

btw, how to put this thread as answered?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.