How to save session variable using PHP into myPHP dbase

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

How to save session variable using PHP into myPHP dbase

Postby Lukas M » 05. August 2019 17:40

Hello,

I was wondering if this is (even) technically possible or whether I am trying something that can not work. I have a database with two tables "users" (username, mail, pwd) and second table "articles" (article name, excerpt, date - and xtra column user).

Using a login script I am able to verify the logged-in users + their passwords against "users" table. Once they are logged in, they can click on a form with two fields "article name, excerpt" fill it in and submit into the database. These data are saved correctly in "articles" table on SQL side.

but can not figure out how to send with the form also the actual "username" that submitted these data. I tried session variable "username" (but that refers to a column in a different table) and as a total beginner I do not know if you can refer to session variables from different tables.
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: How to save session variable using PHP into myPHP dbase

Postby Nobbie » 05. August 2019 21:10

Lukas M wrote: and as a total beginner I do not know if you can refer to session variables from different tables.


Weird question.

There is no relation ship at all between Session Variables and MySQL Tables. Nothing, niente, null.

Any Session Variable can have any value, you can define the name of the variable and the value. Session Variables "survive" between HTML/PHP pages. Thats the ONLY idea of Session Variables. I do not have the slightest idea, why you connect Session Variables to MySQL Tables and columns. There is no such thing in PHP.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: How to save session variable using PHP into myPHP dbase

Postby Lukas M » 05. August 2019 21:21

Thank you for the clarification. I have several pages in a row:

1st page (PHP) contains a login form + post method. that calls "functional PHP script" in a different PHP page handling with dbase, input fields and such
2nd page if the user gets verified, he lands again on a PHP page showing "options - links" avalaible only to logged-in users. One of them is to submit a new article
3rd page. its HTML document containing a tiny form to submit a new article details. FORM method is POST and calls another PHP functional page that inserts data to dbase.

this all works perfectly well if I do not try to use any sesssion handler and stick only to "post" and $variables. The data get into SQL dbase.

but when I try to work with session variable such as .. $_SESSION['uid'] = $_POST['uid']; .. then from the 3rd page not a single field is inserted into dbase. All of the pages " in a row" contain in the header on the first line <?php session_start(); .. (in HTML document its also properly ended). I have read so many articles when this should easily work, and worked for others, but not for me.. could it be the HTML document "in between" that somehow stops the session ID to be handed "from one page to another" .. ?
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: How to save session variable using PHP into myPHP dbase

Postby Lukas M » 06. August 2019 00:16

woohoo.. ! its working now.. the issue was really "stupid".. I had two different versions of the "first PHP page" .. and the script inside the first logon form - either succesful or not, still in header diverted with a login message to the "other" page than I took for granted to be default.. so I changed the paths in all those error / state handlers to a proper PHP page and then - suddenly - i get the username from a session saved in a SQL column.. !

but this so annoying and tricky.. took me maybe 7 hrs to figure it out.. wish that PHP code was more clean and straightforward as CSS or HTML, all these brackets, parentheses, semicolons etc.. its just too confusing.
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: How to save session variable using PHP into myPHP dbase

Postby Nobbie » 06. August 2019 11:01

Lukas M wrote: wish that PHP code was more clean and straightforward as CSS or HTML, all these brackets, parentheses, semicolons etc.. its just too confusing.


Isn't it your code?? Clean it up.

In general, PHP Syntax does not differ greatly from all other well known Computer Languages like C, C++, Java, JavaScript (a special implementation of Java exclusively for Internet browsers) etc., they all look very similar. These are all procedural codes, whereas neither HTML nor CSS is procedural.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: How to save session variable using PHP into myPHP dbase

Postby Lukas M » 06. August 2019 19:47

this line I meant in "general" - not referring to my specific code


wish that PHP code was more clean and straightforward as CSS or HTML, all these brackets, parentheses, semicolons etc.
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: How to save session variable using PHP into myPHP dbase

Postby Nobbie » 06. August 2019 20:03

Actually - i dont understand that. Of course all these "brackets, paraentheses, semicolons" etc. are part of PHP Syntax. A powerfull language needs a powerfull syntax. If you have any suggestions how to improve PHP Syntax - feel free to contact PHP Development.

CSS and HTML are dumb in comparison to PHP; of course it looks easier.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: How to save session variable using PHP into myPHP dbase

Postby Altrea » 06. August 2019 20:35

Lukas M wrote:wish that PHP code was more clean and straightforward as CSS or HTML, all these brackets, parentheses, semicolons etc.

Thats like compairing an abacus with a personal computer. Both can calculate if you feed them with some data.
Of course the abacus looks much more easy but is also much more limited.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: How to save session variable using PHP into myPHP dbase

Postby Lukas M » 07. August 2019 01:21

you are (both) completely right in your statements.. I was just ventilating my "frustration" comparing the fact that CSS comprises only of < > to define some statement .. while PHP and all other programming languages are much more difficult to "grasp" for someone like me used only to < > HTML tags.
Lukas M
 
Posts: 19
Joined: 28. July 2019 15:07
XAMPP version: 7.3.7
Operating System: Windows 7 Pro 64bit SP

Re: How to save session variable using PHP into myPHP dbase

Postby Nobbie » 07. August 2019 11:33

Lukas M wrote: the fact that CSS comprises only of < > to define some statement ..


No, do you really know CSS??

Actually, CSS also uses all kind of brackets, namely "{" and "}", "[" and "]", also "(" and ")". It uses semicolons and commas, it uses colons ":", it uses vertical bar (as well single "|" as double "||"), it uses "+", "-" as combinators, it uses hash symbol "#", it uses dots ".", and and and - for a complete documentation of CSS Syntax and all special characters see https://devdocs.io/css/
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 17 guests