TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-29-2008, 04:43 PM   #1 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default logging in

ok so im a bit stuck on this i have an assignment where i need to Start a session, and maintain it throughout, or until the user selects “logout” (for which a link must be provided). Ask the user’s name, and then display it on every subsequent page. i dont have anywhere on the database server where i can store the username so do i use cookies? im assuming i need to make a form and then save it to a cookie is this right?
any help greatly appreciated
cheers ric
ricrhys is offline  
Reply With Quote
Old 04-29-2008, 05:33 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

If it's just a basic assignment and all you have to do is get that users name to be displayed until they choose to log out, it's really quite easy. I can't do it for you, because it's your homework, but I can nudge you in the right direction pretty far.

session_start()
$_SESSION superglobal

That should be all you need, along with $_POST and one form to ask them their name. One if statement and your logout can be taken care of in one method call too.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-29-2008, 07:37 PM   #3 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

Maybe I'm horribly out of the loop, but...Schools offer PHP otherwise known as web development classes?

On a related note, Delayed is right check out sessions or even cookies.
__________________
"What everyone seems to forget is that while knowledge certainly is something - it's the implementation of knowledge that brings power" - Andres Galindo.
TlcAndres is offline  
Reply With Quote
Old 04-29-2008, 08:44 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
Originally Posted by TlcAndres View Post
Maybe I'm horribly out of the loop, but...Schools offer PHP otherwise known as web development classes?
Depends on the school, I'm sure. I'm currently getting my Bachelors of Science in what they called Interactive Media Design which covers PHP and MySQL for a few quarters.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-30-2008, 02:27 PM   #5 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

cheers guys got the log in bit working now, but the session start seems to be giving me an error Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /berw/ugrad1/base/r/rre7/public_html/sonicandtails/test.php:2) in /berw/ugrad1/base/r/rre7/public_html/sonicandtails/test.php on line 3

any ideas why its doing this
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 03:09 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by ricrhys View Post
cheers guys got the log in bit working now, but the session start seems to be giving me an error Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /berw/ugrad1/base/r/rre7/public_html/sonicandtails/test.php:2) in /berw/ugrad1/base/r/rre7/public_html/sonicandtails/test.php on line 3

any ideas why its doing this
Yes, you cant do session_start after the headers have ended. This is either caused by you outputting anything. Simply put, you must do that command before you output a line of text.
__________________

Village Idiot is offline  
Reply With Quote
Old 04-30-2008, 02:30 PM   #7 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

thatll be the white space
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 02:59 PM   #8 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Get er fixed then?
delayedinsanity is offline  
Reply With Quote
Old 04-30-2008, 03:33 PM   #9 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

yeah got it half fixed cheers
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 03:40 PM   #10 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

i need to be able to let the user search my database and say for example i would like to search for games under £30, i know how to write the form but am not sure about the code in psuedo itd be something
like, if < is selected and input is 30 show results from table with price < 30
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 03:47 PM   #11 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

How is your data being stored, in a flat text file, or an SQL database?
delayedinsanity is offline  
Reply With Quote
Old 04-30-2008, 04:05 PM   #12 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

in a sql database
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 04:12 PM   #13 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

SELECT field1, field2 FROM games WHERE price < 30
SELECT field1, field2 FROM games WHERE price BETWEEN 1 AND 30

unless you mean the PHP code

PHP Code:

switch ($_POST['amount']) {
     case 
"30"// build your query
     
case "60"// build your query
     
default: // SELECT *

is one method. You may want to check out php.net and look up "control structures".
-m
delayedinsanity is offline  
Reply With Quote
Old 04-30-2008, 04:33 PM   #14 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

yeah its the php code. im checking on .net now but not having too much joy, the user needs to be able to specify the amount they want so it could be any amount, i need to take the out put from a txt field and use it to display the suitable results here is my page just so you see what i mean Sonic And Tails Online Game Shop "The One Stop Shop For All Your Gaming Needs"
cheers for your help by the way
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 04:42 PM   #15 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

You should be able to use the value they enter into the form field (via $_POST['field']) and use that in your SQL query to determine what data to return. The only thing I would suggest on top of that, is validate your form input. Make sure if you need an integer, you're getting an integer, for example.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-30-2008, 05:11 PM   #16 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default

getting lost doh! sorry to keep bugging you, do i still have all the same stuff as for the whole table but then when it gets to the "while" thats where i have to change yes? how do i tell the table to return whats lower or higher than the $_POST[price]

<?php $conn = pg_connect("host=database.dcs.aber.ac.uk
port=5432 dbname=teaching
user=csguest password=rohishe");
$conn = pg_connect("host=database.dcs.aber.ac.uk
port=5432 dbname=teaching user=csguest password=******");
$res = pg_query ($conn, "select * from TopGames");
echo "<table border='1'>";
while ($a = pg_fetch_row($res)) {
echo "<tr>";
for ($j = 0; $j < pg_num_fields($res); $j++) {
echo "<td>" . $a[$j] . "</td>";
}
echo "</tr>";}
echo "</table>\n";?>

Last edited by ricrhys : 04-30-2008 at 06:15 PM.
ricrhys is offline  
Reply With Quote
Old 04-30-2008, 06:18 PM   #17 (permalink)
The Wanderer
 
ricrhys's Avatar
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
ricrhys is on a distinguished road
Default so ive got this far

ok so ive got this far but its not quite right can anyone help its displaying all sorts of prices


PHP Code:
More Search options&nbsp<select>
  <option>More Than</option>
  <option>Less Than</option>
  <option></option>
</select><form method="post" action="results.php"><input type="text" name="price" /><input type="submit" /></form>
    <?php $conn pg_connect("host=database.dcs.aber.ac.uk
port=5432 dbname=teaching
user=csguest password=rohishe"
);
$conn pg_connect("host=database.dcs.aber.ac.uk
port=5432 dbname=teaching user=csguest password=******"
);
if (
array_key_exists("lessthan"$_POST))
$res pg_query ($conn"select * from TopGames where price < $_POST[price]");
else 
$res pg_query ($conn"select * from TopGames where price > $_POST[price]");


echo 
"<table border='1'>";
while (
$a pg_fetch_row($res)) {
echo 
"<tr>";
for (
$j 0$j pg_num_fields($res); $j++) {
echo 
"<td>" $a[$j] . "</td>";
}
echo 
"</tr>";}
echo 
"</table>\n";?>
ricrhys is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:41 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design