some queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

some queries

Post by rami »

problem1)
the user name and password are stored in database table ..the user enter username and password and it is checked against the password and username in tables
now problem is if uname and pass are correct i want user to direct to thier personal profile page...if user can see only his personal profile

how is it done ?

is it making query
select .....from tables where uname=required and pass=" "

or we make separate page for each

are there simple example code in any web site

query 2) does php run in IIS (other than in aphace)
i am unable to make in run in IIS though some books says it can
then how

query 3)
when searching i want to search in certain tables only how it can be done
i want search result from password protected area
how it is done

query 4)
there is a box ,and a form when data are entered from that form it goe to database and content are displayed in box..just like message board
problem is when new message is post i want old to go to archive and new one to be in box(only that one )
can can it be done
any example codes to download

if some body provide me with sample codes for this question may be s/he will be my guru in php ...as i am a begineer
thanks for your replies
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

query 1:

redirect with header() and set a $_SESSION with information to let the website know they logged in successfully and who they are. just have 1 page for every person to view their profile but make it so it builds the page off of the username that is the $_SESSION username for that person.

2:

php does run on windows, google for php install for windows and you will find it for sure

3:

please make your question clearer, like you can do

Code: Select all

SELECT
*
FROM
table
WHERE
somthing = somthingelse
then use some LEFT JOIN and whatnot to string together whatever tables you want

4:

once again i have no idea what you said
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

for 4), i think what you mean is you want only the latest message to be shown in the box and the rest goes to archive (or not shown).

If the table you store the messages has a timestamp, then you can sort the table with descending time and limit the result to only one:

Code: Select all

SELECT * FROM messages ORDER BY timestamp DESC LIMIT 1
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

Post by rami »

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


thanks for replies ..actually its kind programmer like you who are increasing the number of php user .Really thanks for trying to help.

[quote="shiznatix"]query 1:

redirect with header() and set a $_SESSION with information to let the website know they logged in successfully and who they are. just have 1 page for every person to view their profile but make it so it builds the page off of the username that is the $_SESSION username for that person.
[/quote]
any specific examples suppose i have this

Code: Select all

require_once ('../mysql_connect.php'); // Connect to the database.
	
	function escape_data ($data) { // Function for escaping data.
		global $dbc;
		if (ini_get('magic_quotes_gpc')) {
			$data = stripslashes($data);
		}
		return mysql_real_escape_string(trim($data), $dbc);
	}

	if (empty($_POST['username'])) { // Validate the username.
		$u = FALSE;
		echo '<p>You forgot to enter your username!</p>';
	} else {
		$u = escape_data($_POST['username']);
	}
	
	if (empty($_POST['password'])) { // Validate the password.
		$p = FALSE;
		echo '<p>You forgot to enter your password!</p>';
	} else {
		$p = escape_data($_POST['password']);
	}
	
	if ($u && $p) { // If everything's OK.
	
		// Query the database.
		$query = "SELECT user_id, first_name FROM users WHERE username='$u' AND password=PASSWORD('$p')";		
		$result = @mysql_query ($query);
		$row = mysql_fetch_array ($result, MYSQL_NUM); 
		
		if ($row) { // A match was made.
				
				// Start the session, register the values & redirect.
				session_start();
				$_SESSION['first_name'] = $row[1];
				$_SESSION['user_id'] = $row[0];
				
				ob_end_clean(); // Delete the buffer.
				
				[color=blue]header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php");[/color]			exit();
				
		} else { // No match was made.
			echo '<p>The username and password entered do not match those on file.</p>'; 
		}
		
		mysql_close(); // Close the database connection.
can i do some thing with that blue code as it gets to only one page..when you say i need to make separatepage for every user then how can i redirect them ...
i am really confused....

what is done..?
the pages which need password are kept in one folder and whole folder pages are programmed password requring
or we include password ,login script in each page ...how is it done...

i am really confused but got some thing may be little help i can solve it...
shiznatix wrote: 2:
php does run on windows, google for php install for windows and you will find it for sure
i am not able to run php codes in IIS ,by the way can't we code in may be notepad save it as php and run in IIS.
shiznatix wrote: 3:
please make your question clearer, like you can do

Code: Select all

SELECT
*
FROM
table
WHERE
somthing = somthingelse
then use some LEFT JOIN and whatnot to string together whatever tables you want
i mean there is one folder or page that content bio data of teachers and next folder containing biodata of students when search is made search should not contain results from teachers pages or should not display teacher password protected pages..

shiznatix wrote: 4:
once again i have no idea what you said
but i think u understood must of the things

any way next user has answered it.By the way how can we create a link to the pages that has gone to archive...

really thanks for your help.I think this site can make me programmer..
thanks
rami


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

In the user page you can call session_start() again, and all the $_SESSION variables would be available to use. Then just build the page off them.

For instance,

Code: Select all

<?
session_start();

$userID = $_SESSION['user_id'];
$query = "SELECT * FROM users WHERE user_id='$userID'";

.....
?>
Post Reply