nav33n 472 Purple hazed! Team Colleague Featured Poster

If your problem is fixed, why not mark this thread as solved ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) Great ! congrats !

nav33n 472 Purple hazed! Team Colleague Featured Poster
$q="select * from user_table where username='$user' and password='$password'"; //when the user is logging in
$result=mysql_query($q);
if(mysql_num_rows($result) > 0) {
echo "Valid user";
while($row=mysql_fetch_array($result)){
$id=$row['id']; //is the autogenerated id
echo "Id is ". $id; //$id will have the id
}
} else {
echo "Invalid user";
exit;
}

Something like that ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="pa"; // Database name
$tbl_name="user"; // Table name
 // Get info from the session

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];


//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
//$result=mysql_query($sql);


$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");

$result2=mysql_query($sql);


// Mysql_num_row is counting table row
$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1 ) {
//Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myusertype");
  if($myusertype=="admin") {
   header("location: admin/index.php");
  } else if($myusertype=="staff"){
  header("location: staff/index.php");
  } else if($myusertype=="student"){
  header("location: student/index.php");  
} else {
 echo "Wrong usertype"; 
exit;  
}
}
else {
echo "Wrong Username or Password";
}

//ob_end_flush();
?>

If this doesn't work, I dont think I can help you with this.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, You have so many "important" lines commented ! wait.. I ll edit my previous post. And I don't think it was working earlier.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You don't need a login_success.php page. Instead of redirecting to login_success.php page, redirect directly to admin/student/staff page ! This would be your new checklogin.php

<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="pa"; // Database name
$tbl_name="user"; // Table name
 // Get info from the session

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];


//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
//$result=mysql_query($sql);


$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");

//$result2=mysql_query($sql);


// Mysql_num_row is counting table row
//$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1 ) {
//Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myusertype");
  if($myusertype=="admin") {
   header("location: admin/index.php");
  } else if($myusertype=="staff"){
  header("location: staff/index.php");
  } else if($myusertype=="student"){
  header("location: student/index.php");  
} else {
 echo "Wrong usertype"; 
exit;  
}
}
else {
echo "Wrong Username or Password";
}

//ob_end_flush();
?>

Try this.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) umm.. No.. Can you post the code of check_login.php ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

No dude! when the user enters the username and password, how will you know if he's a valid user and not a dummy one ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Where are you validating the login ? When the user enters his username and password, where are you checking if he's a valid user ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, then depending upon the input of the user, you can redirect him to relative page. According to you, the user enters the usertype in the textbox myusertype. When the user submits the page, get the value of myusertype.

$usertype=$_POST['myusertype'];
if($usertype=="student"){
 //redirect to student page
} else if ($usertype=="admin") {
 //redirect to admin page
} else if($usertype=="staff"){
  //redirect to staff page
} else { // none of these 3 users
 //redirect to error page
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

How do you differentiate whether a user is an admin or a staff member or a student ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

line 34. I think thats a comment missing "//"

nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. is menuassignment an array and are you trying to assign that array to $expected ? Sorry for my ignorance, but I still don't get it. What is the problem exactly ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

What is this $expected = array('menuassignment'); for ? Where are you using it ? What is the array you are trying to validate ? Could you explain your problem in detail ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Code please!

nav33n 472 Purple hazed! Team Colleague Featured Poster

$a="array(";
$a.="10)";
is different from $a=array("10");

Because in the first case, $a is considered as a string, since "array(" is in double quotes. In the second case, $a is declared as an array. Instead of assigning the value to $a, you can do it this way.

$values="";
for($i=0;$i<10;$i++){
$values.=$i.";";
}

So, by the end of the loop, $values will have a collection of values separated by ;. You can then assign this value to an array by exploding it.
ie., $a=explode(";",$values); So, $a will have an array of values.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great!

@niek_e congrats :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

restart your apache and try again ! If that doesn't work, then please check what niek_e has posted.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Again, check the file you are changing. Because, if you change the values of php.ini, it *has* to change. If it doesn't, then you are changing the wrong file.

nav33n 472 Purple hazed! Team Colleague Featured Poster

/var/lib/php/session Create a folder called php and under that, create session. Then try !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Also check if /var/lib/php/session exists. The rest seems to be ok!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do it with cookies, i guess. I haven't used cookies much, so I am not much aware of its functions.
Can you show us whats in your php.ini ? (in [session] part)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi. Welcome to Daniweb. Your question is nowhere related to php. You can post your question in geeks' lounge forum! or even better, google it !

nav33n 472 Purple hazed! Team Colleague Featured Poster

huh! Check this link. Maybe you will find your answer in that thread !

nav33n 472 Purple hazed! Team Colleague Featured Poster

How bout another simple example.

<?php //page1.php
session_start();
$_SESSION['name']="something";
echo $_SESSION['name'];
header("location: page2.php");
?>
<?php //page2.php
session_start();
echo $_SESSION['name'];
?>

Does this work ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try out a simple example.

<?php
session_start();
$_SESSION['name']="something";
echo $_SESSION['name'];
?>

Tellme if that works.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you explain in detail what exactly you mean by that ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

small mistake. Try this.

<table width="1000" height="95" border="1">
  <tr>
    <td bgcolor="#0000FF">&nbsp;</td>
  </tr>
</table>

<center>

<?
   include("connect.php"); 
      //this is your validation in the form,put it here....
       if (empty($_POST['name']))
      { 
      $errors[] = 'Please enter a name';
      }
      if (empty($_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", 
      $_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      if (empty($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with numeric value';
      }
      else if (!is_numeric($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with a numeric value';
      }
      
      
      if (empty($_POST['person_attend']))
      {
      $errors[] = 'Please enter some word for person attend';
      }
      
      
      else if (strlen ($_POST['person_attend']) > 255)
      {
      $errors[] = 'person attend';
   }
   
   
   
      if (empty($_POST['comment']))
      {
      $errors[] = 'Please enter some comment';
      }
      else if (strlen ($_POST['comment']) > 255)
      {
      $errors[] = 'comment ';
  
 }
 
      $name = $_POST['name'];
 
      $email = $_POST['email'];
 
      $contact = $_POST['contact'];
 
      $person_attend = $_POST['person_attend'];
  
      $comment = $_POST['comment'];
 
      
 
 
      if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" )
      
      {
 //process form
 
      //this is your add query....
  
      $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
   
      VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";
      
      $results = mysql_query($query) or die ("Could not execute query : $query." . mysql_error());
		if($result){
      echo "thanks you ";
		}
       mysql_close();
     
 
      } else {
 if(isset($errors))
{

	foreach($errors as $val)
	{
	
		echo "Error: $val <br/>"; 
	}
}
      	
      }
 
      
      

?>
</center>
<center> 
<br>
<a href="Index.php">View list attend</a><br>
<a href="register.html">Clik here to register</a>
</center>

If that doesn't work, then you have to check the flow …

nav33n 472 Purple hazed! Team Colleague Featured Poster

echo $a."<br />"; //Note this outputs array(0, 204, 460, 586, 709, 826) in browser as desired and expected

If $a was an array, It wouldn't print anything if you give echo $a. It will give aray().
So, obviously,

foreach($a as $s) {
echo "Value: " . $s . "<br />";
}

that wouldn't work since foreach takes an array as an argument. I don't think $a stores an array.

nav33n 472 Purple hazed! Team Colleague Featured Poster
<table width="1000" height="95" border="1">
  <tr>
    <td bgcolor="#0000FF">&nbsp;</td>
  </tr>
</table>

<center>

<?
   include("connect.php"); 
      //this is your validation in the form,put it here....
       if (empty($_POST['name']))
      { 
      $errors[] = 'Please enter a name';
      }
      if (empty($_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", 
      $_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      if (empty($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with numeric value';
      }
      else if (!is_numeric($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with a numeric value';
      }
      
      
      if (empty($_POST['person_attend']))
      {
      $errors[] = 'Please enter some word for person attend';
      }
      
      
      else if (strlen ($_POST['person_attend']) > 255)
      {
      $errors[] = 'person attend';
   }
   
   
   
      if (empty($_POST['comment']))
      {
      $errors[] = 'Please enter some comment';
      }
      else if (strlen ($_POST['comment']) > 255)
      {
      $errors[] = 'comment ';
  
 }
 
      
 
 
      if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" )
      
      {
 //process form
 
      //this is your add query....
  
      $name = $_POST['name'];
 
      $email = $_POST['email'];
 
      $contact = $_POST['contact'];
 
      $person_attend = $_POST['person_attend'];
  
      $comment = $_POST['comment'];
 
      $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
   
      VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";
      
      $results = mysql_query($query) or die ("Could not execute query : $query." . mysql_error());
		if($result){
      echo "thanks you ";
		}
       mysql_close();
     
 
      } else {
 if(isset($errors))
{

	foreach($errors as $val)
	{
	
		echo "Error: $val <br/>"; 
	}
}
      	
      }
 
      
      

?>
</center>
<center> 
<br>
<a href="Index.php">View list attend</a><br>
<a href="register.html">Clik here to register</a>
</center>

Try this.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) lol.. congrats ! finally the problem is solved!

nav33n 472 Purple hazed! Team Colleague Featured Poster

When the user logs in, check if he's a valid user. If he's a valid user, add that username to a session variable. Use that session variable in the next page where you want to display his name. A small eg.

<?php //page1.php
session_start();
// check if the user is valid
if (valid user){
$_SESSION['username']=$username;
redirect to page2.php
} else {
 //error message
}

And this is page2.php

<?php
if(isset($_SESSION['username'])){
 echo "Welcome ". $_SESSION['username'];
} else {
  echo "Not logged in ! ";
  exit;
}

Hope that helps.

nav33n 472 Purple hazed! Team Colleague Featured Poster

hmm..Your above script should definitely work.. Check your php.ini file for session.
Check for these lines and if its commented, uncomment it.

session.save_handler = files
session.use_cookies = 1

.
If this doesn't work, then I can't do much about it.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Replace if(1==2) with

if(!$_POST['username'] || !$_POST['pass']) {
die('You did not fill all the fields.');
}

and leave the else part as it is.

nav33n 472 Purple hazed! Team Colleague Featured Poster

php and apache versions doesn't matter.
Check the loop, I have added if(1==2) which will always fail. Replace it with your validation part.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I have modified your code to test it and it works. Here's the code. Modify it again to meet your requirements.

<?php //login1.php
session_start();
ob_start();
?>
<?php
//if login form is submitted

if(1==2) {
die('incorrect password,please try again.');
}
else
//if login is ok then direct them to options page
{
$_SESSION['views'] = 1;	
header("Location:option1.php");	
ob_flush();

?>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=option1.php">
<?php
}
?>

And here is option1.php

<?php 
session_start();
ob_start();
if(isset($_SESSION['views'])) {
$_SESSION['views']=$_SESSION['views']+1;
echo $_SESSION['views'];
}
else
{
//header("Location:message.php"); 
echo "session not set"."</br>";	
print_r($_SESSION);
}
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't see anything wrong with the code apart from this line. if(!$_POST['username'] | !$_POST['pass']) { It should have been if(!$_POST['username'] || !$_POST['pass']) { . Thats just a syntax error. The code isn't long ! lol.. it has just 80+ lines. Anyway, Check if its entering the else { $_SESSION part. If its entering the else part, remove the meta tag and try again..

Edit: And btw, <!META HTTP-EQUIV="Refresh" CONTENT="0; URL=option1.php"> is wrong. What is "!" doing there ?

Edit 2: And, you are not printing $_SESSION in page 2 :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Then code please !

nav33n 472 Purple hazed! Team Colleague Featured Poster

are you putting session_start() at the top of all the pages that require the session?

You beat me by few seconds :P

nav33n 472 Purple hazed! Team Colleague Featured Poster

Are you starting the session in page2 ? If your answer is yes, then you need to show us your code. If your answer is no, then start the session ! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

mysql_fetch_array does the work of both mysql_fetch_row and mysql_fetch_assoc. (mysql_fetch_array can take an extra parameter!). Anyway, stripslashes just takes off the added slashes. unless you are storing the values using addslashes, You don't have to use stripslashes. Print out what's in $category. If it has slashes, then probably, that slash 'escaped' the " character and maybe that was the reason you were getting null ?

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Are you working on linux by any chance ? Because in linux, the column names are case-sensitive. If you use $list in your query and you have NAME as a column name, then it would return null ! That might be the problem. Print out $list. There must be something wrong ! And check this link for the syntax of heredoc.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome man! And yep, we learn something new everyday !

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can extend the maximum execution time by changing max_execution_time in php.ini to whatever amount you want. You can remove the time limit by setting it to 0. If you want to change it during the runtime, use set_time_limit(0); in your script.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Check your loops. I guess you have an infinite loop somewhere OR maybe the queries to fetch the data from the table is taking a long time. Umm.. I think the problem is with the loops!

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can try Notepad++ or devphp. There are many more free ide's available. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

its not
$_SESSION('u_name') = $usr_nam_chk_avail; But the one I posted above.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Its $_SESSION=$usr_nam_chk_avail;

nav33n 472 Purple hazed! Team Colleague Featured Poster

On successful registration, add username to the session. In the next page, check if session is set, if yes, then redirect directly to the page which he gets after successful login. If session is not set, redirect him to login page.