Jump to content

Pls HELP.. i need it badly.. :(


vinsux

Recommended Posts

The logic of my code is Suppose that the student is already logged in his account..

there's a page where it restricts a user to enter the page and he needs to register on that page..

without entering any details or it's just a button saying "Ask To Join"..

Please.. people with a good heart.. pls. help me... it will be very much appreciated.. Thank you very much..

There's no syntax error.. but it directly goes to verified.php but the user needs to be verified..

 

to explain it simply, it's just like the YAHOO GROUPS.. where you need to join to access the group..

 

<?php 
mysql_connect("localhost","root","") or die(mysql_error()); 
mysql_select_db("login") or die(mysql_error()); 

$errors="";
$message="";

$username = $_COOKIE['ID_my_site']; 

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


		$check = "SELECT $username FROM students";
		$result = mysql_query($check) or die(mysql_error());
		while($row = mysql_fetch_array($result))
				 {
			 $id = $row['id'];
				 $username = $row['username'];
			 $namelast = $row['namelast'];
				 $namefirst = $row['namefirst'];
			 $namemi = $row['namemi'];
			 }
			$insert = "INSERT INTO pendings (id, username, namelast, namefirst, namemi)
			VALUES ($id, $username, $namelast, $namefirst, $namemi)";
			$add_member = mysql_query($insert) or die(mysql_error());	

			if (mysql_affected_rows()==1){
				$message .= "<h1>Registered</h1>
				<p>Thank you, Please wait for the approval of the faculty teacher who handles the subject.</p>";
			}
		}
	else
	{
	 header("location:verified.php"); 
	}

?>

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


        <br />
                  <input type="text" name="username" maxlength="60"value="$usernamet"/>
	<input type="text" name="username" maxlength="60"value="$namelast"/>
	<input type="hidden" name="namelast" maxlength="20" value="$namefirst ?>" />
        <input type="hidden" name="namefirst" maxlength="20" value="$namemi" /><
	<input type="hidden" name="namemi" maxlength="20" value="$id" />

	<center><br /><br /><input type="submit" name="submit" value="Ask to Join"  style="width: 100px; height: 30px"/></center>

</form>

Link to comment
Share on other sites

Well, it seems pretty obvious to me. I'm not going to give you a solution as this seems like a homework problem, but I'll help illuminate the problem.

 

You first do a query to get a matching record (if one exists). Assuming that query does not fail, it will return a result - even if that result is empty. Then you have a loop to populate the results of the query into variables. NOTE: I would assume there should only be 0 or 1 results from the query. So, a loop is unnecessary. Anyway, if 0 records were returned from that first query the only difference up to this point would be that the variables would not be defined.

 

After the loop to process the records you generate an insert query and run it. If you don't have error reporting set to show ALL errors/warning those undefined variables will be replaced with empty string in that INSERT query. Then, after the insert query, you check the affected rows. Well, if the values for some of the fields in the query are empty strings and those fields allow empty values the INSERT query will still succeed - you will just have a mostly empty record.

 

Your check for whether the user exists or not should be done based upon the result of the first query.

Link to comment
Share on other sites

Thank you very much,.. it worked now,

but my problem now is how to know if the user is registered on that group..

I'm sorry i'm newbie on php, i just analyzing the codes what i saw on the tutorials..

 

"You first do a query to get a matching record (if one exists). Assuming that query does not fail, it will return a result - even if that result is empty. Then you have a loop to populate the results of the query into variables. NOTE: I would assume there should only be 0 or 1 results from the query. So, a loop is unnecessary. Anyway, if 0 records were returned from that first query the only difference up to this point would be that the variables would not be defined."

 

 

Is it the one that i need to do? I'm sorry, i can't analyze the flow of that scenario

Thank you very much again for your help.. Sir Psycho and Sir Barand

 

 

<?php 
mysql_connect("localhost","root","") or die(mysql_error()); 
mysql_select_db("login") or die(mysql_error()); 

$errors="";
$message="";

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

	 if(isset($_COOKIE['ID_my_site']))
			{
		$username = $_COOKIE['ID_my_site']; 

		$result = mysql_query("SELECT * FROM students  WHERE username = '$username'");

		while($row = mysql_fetch_array($result))
    			{
     			   //prints output lines
			 $un = $row["username"];
			 $nl = $row["namelast"];
			 $nf = $row["namefirst"];
   			     $mi = $row["namemi"];
  			 	 }

			$insert = "INSERT INTO pendings (username, namelast, namefirst, namemi)
			VALUES ('$un', '$nl', '$nf', '$mi')";
			$add_member = mysql_query($insert) or die(mysql_error());	
				if($add_member) 
					 header("location:verified.php");
				else 	
					print("data not inserted");

		}
	else
	{
		 	 header("location:verified.php");

	}
}
?>

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

	<br />
        <h2>  _________________________________________________________________________</h2>
        <br />
	<center><br /><br /><input type="submit" name="submit" value="Ask to Join"  style="width: 100px; height: 30px"/></center>
      <br />
      <h2>  _________________________________________________________________________</h2>
      <br /><br />
      <br /><br />
</form>

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.