473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Session Data - Newbie to PHP

201 100+
Hello -

as the title states i'm a newbie to php!

This is what i would like to do:

start a session to caputure data from the user
then when they submit the data to be stored in mysql db
the page will redirect into another page on the form action.

i've googled on session and cookies! and i went to php.net but not really any good learn by examples.

My background consists of all back end work i.e. dba admin!

Thanks, in advance for you help!
Jan 28 '09 #1
8 1555
TheServant
1,168 Expert 1GB
Hi there,
PHP is a server side script, so you might want to read up on what that means if you don't already know. To start a session, above every page that you would like to use $_SESSION variables include "start_session();". This should be the very first thing on the page because if ANY page output is before it, it will print an error along the lines of "Headers already sent" if I remember correctly.

Forms can be submitted to a PHP page, but this is a big topic and I recommend you start reading tutorials (like http://www.tizag.com/phpT/) which is where I started about a year ago. Above the PHP handling of the form variables, then using PHP you prepare the data to put into your MySQL query which you will also need to read up on.

This site is really for helping people with code, or responding to specific questions, so have a go, and if you get stuck, post what you have so far and we can help. It's really hard to know what you have already in terms of code or knowledge from your post, but if you post your code, we'll know ;)
Jan 28 '09 #2
wizardry
201 100+
Thanks for the response! I've looked into them (tizag) but it was to basic. I understand how the session() works, but how to use it is another story.

I see that he was trying to assign variable to it that fines but i want to assign a session id. is that auto generated through your web server or can you call it from the database?

here is the sample code so far.

i'm query the database for data to be displayed on the page in this .php.

editPage.php


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $extra = "testProfile.php";
  3. $dom = "xxxx";
  4. header("Location: http://localhost/$dom/$extra");
  5. ?>
  6. <html>
  7. <head>
  8. <title>Really Simple CMS</title>
  9. </head>
  10. <body>
  11. <h1>Really Simple CMS</h1>
  12. <?php
  13. mysql_connect("localhost", "xxxx", "xxxx");
  14. $result = @mysql_query("SELECT contents from cms.page");
  15. while ($row = mysql_fetch_assoc($result)){
  16. $contents = $row['contents']; // Do not change these to angle brackets
  17. }
  18. //exit;
  19. ?>
  20. <form name="form1" method="post" action="updatePage.php">
  21. <br />Enter page content:<br><textarea rows="10" cols="60" name="contents"><?php echo "$contents" ?></textarea>
  22. <input type="submit" name="Submit" value="Update Page">
  23. </form>
  24. <?php
  25. exit;
  26. ?>
  27. </body>
  28. </html>
this one processed the data update.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $contents=$_REQUEST['contents']; // Do not change to angle brackets
  3. mysql_connect("localhost", "xxxx", "xxxx");
  4. $result = @mysql_query("UPDATE cms.page SET contents='$contents'");
  5. mysql_close();
  6. ?>
---------------------------------------------------------------------------------

this is the form that is called by redirect in edit.php

this created the new form layout for that query, but instead of parsing data through out pages, i would like to use session.


Thanks, in advance for you help.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // create the file to open to process the data
  3. $test = "X:\\xxxx\\htdocs\\xxxx\\test.php";
  4. $t1 = fopen($test, 'w' ) or die ( "can not create file");
  5. // send the data to the file including layout
  6. $stringData = "X:\\xxxx\\htdocs\\xxxx\\testFile.txt";
  7. fwrite($t1, $stringData);
  8. //close stream
  9. fclose($t1);
  10. //exit;
  11. ?>
Jan 28 '09 #3
wizardry
201 100+
i will continue looking for Relative Data on Session's during the mean time.

Thanks
Jan 28 '09 #4
Markus
6,050 Expert 4TB
I don't quite understand why you need sessions for handling data if your form is sending the data. Anyway, check these links out

http://uk2.php.net/manual/en/function.session-id.php
http://uk2.php.net/manual/en/ref.session.php
Jan 28 '09 #5
wizardry
201 100+
thanks for the update will check it out!
Jan 28 '09 #6
wizardry
201 100+
that will do thanks markus.

do you happen to have a list or know of a list of do's and don'ts to web programming ( Front End )

Thanks
Jan 28 '09 #7
Markus
6,050 Expert 4TB
@wizardry
Only one I can think of at the moment: keep your display logic seperate from your business logic. Once you have gotten comfortable in PHP, I would suggest you then start learning some programming design patterns. Also, look into some frameworks (I suggest CodeIgniter); they'll make your life a lot easier.

If you ever hit a problem or have a more specific question, be sure to start a thread here.

Markus.

PS: You should validate your user input!!
Jan 28 '09 #8
Atli
5,058 Expert 4TB
@wizardry
I don't know of such a list (although I suspect Google might know a few).

But, rules #1 through 5 of web programming are (or should be):
  1. Validate your user input!
  2. Validate your user input!
  3. Validate your user input!
  4. Validate your user input!
  5. Validate your user input!
Might seem obvious, but this is the #1 reason for security vulnerabilities in websites.
Jan 29 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Arnaud | last post by:
Hi ! I would like to propagate data between php pages, in two cases : the pages are read by : 1- Internet Explorer It's ok, data are writen in one page, and read from another. I don't use...
2
by: Newbie | last post by:
Hi All, I would really appreciate any ideas / clues on this issue which I am facing. I have a asp.net application, the problem is with maintaining session variables while using authentication for...
7
by: Mr Newbie | last post by:
I have written a Custom Control Menu. Its fairly simple but it works well enough. In order to simplify things I decided to store the Menu1 custom control in Session. In the page load event below,...
2
by: Steven | last post by:
In my code I assign a value to a session variable such as Session("CustID")=Customer. The value persists until I hit a command button. When this occurs the code before the 'If Not IsPostBack Then' ...
5
by: desh | last post by:
helo friends I m newbie in PHP . I m not able to know what exactly the use of session is. How can one keep the track of users using Session.. Desh
2
by: Ned Balzer | last post by:
Hi, Apologies if this is a newbie question, I haven't found the answer in any faqs. I have an asp.net 2.0 page that sets session variables and then redirects to another page. For the page...
5
by: Twayne | last post by:
Hi, If ever a newbie wants to know how much he has to learn yet, he only has to look here<g>!! ANYway: PHP 5.2.5; XP Pro SP2+, local Apache Server My actual question is: How do I get a...
1
by: rsandes1 | last post by:
Hello, still a newbie here, Does anyone know how to use a session variable like "UserId" column as a parameter within a object data source. The options that I have are "querystring", "control",...
7
by: lak | last post by:
I want to study about the Session handling in PHP. I don't know where to start. So please suggest me some way.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.