 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
04-29-2008, 04:43 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
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
|
|
|
|
04-29-2008, 05:33 PM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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 meth od call too.
-m
|
|
|
|
04-29-2008, 07:37 PM
|
#3 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 264
Thanks: 2
|
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.
|
|
|
|
04-29-2008, 08:44 PM
|
#4 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Quote:
Originally Posted by TlcAndres
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
|
|
|
|
04-30-2008, 02:27 PM
|
#5 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
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
|
|
|
|
04-30-2008, 02:30 PM
|
#6 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
thatll be the white space 
|
|
|
|
04-30-2008, 02:59 PM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Get er fixed then?
|
|
|
|
04-30-2008, 03:09 PM
|
#8 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,298
Thanks: 17
|
Quote:
Originally Posted by ricrhys
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.
|
|
|
|
04-30-2008, 03:33 PM
|
#9 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
yeah got it half fixed cheers
|
|
|
|
04-30-2008, 03:40 PM
|
#10 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
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
|
|
|
|
04-30-2008, 03:47 PM
|
#11 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
How is your data being stored, in a flat text file, or an SQL database?
|
|
|
|
04-30-2008, 04:05 PM
|
#12 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
in a sql database
|
|
|
|
04-30-2008, 04:12 PM
|
#13 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-30-2008, 04:33 PM
|
#14 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
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
|
|
|
|
04-30-2008, 04:42 PM
|
#15 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
04-30-2008, 05:11 PM
|
#16 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
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.
|
|
|
|
04-30-2008, 06:18 PM
|
#17 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 9
Thanks: 0
|
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 <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";?>
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|