Making a new .html form for users - how to get user name?

Started by Katsulynx, August 12, 2011, 12:11:24 PM

Previous topic - Next topic

Katsulynx

Hey everyone,

I am about to write a new registration page for some stuff for my forum but actually I don't know how to solve my problem...
I allready coded how the page should look like and the form itself, which is allready insering everything in the data base except the user who is sending... Now I would like to know how i could tell my script who the user is and what his ip is so it can insert it into the database. Does anyone have an idea for me?

IchBin™

You can't just use straight HTML for that. Your form page will have to use PHP to grab that data.

$user_info['name'] has the username stored in it.

To get the user's IP you could also use $user_info['ip'] to get that info.
IchBin™        TinyPortal

Katsulynx

Thanks for the help. I tried to add those two lines into my process.php als well as into my .html-document, but unluckily, it did'nt work at all...

I added it into my html-page like that:
    <?php
  $user_info
['name'];
$user_info['ip'];
$ip=$user_info['ip']
$name=$user_info['name']
?>

directly under the java-script which is at the beginning of the header. There is no error when sending the form to the database, it is sucessfully added, but the field with the name and the ip still remain empty.
With the information that is set in the header, the form fills in itself:
<input type="hidden" name="ip" value="$ip">
<input type="hidden" name="name" value="$name">

and at last, the process.php gets the information like any other else:
$name=$_POST['name'];
$ip=$_POST['ip'];


Joker™

Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

IchBin™

How are you pulling the variables into your page? Are you including SSI.php or something?
IchBin™        TinyPortal

Katsulynx

Edit:
I now changed the page to an .php page following the tutorial in this forum. [nofollow] But to be honest, I dont know where to add the codes you gave me now... I want to fill the variables $name and $ip with the current users name and ip, which are then added to their fields automatically:
<input type="hidden" name="id" value="$ip">
<input type="hidden" name="name" value=""$name">


and maybe someone can help me with integrating a javascript in this page which tests whether all fields are filled out or not, because there is no header to integrate it in and if I make one, there is an error on the final page which says, that the page already gots his header from the subs.php

IchBin™

Sorry don't have the time as I'm headed out the door. However a quick explanation is in order. When you want to output a variable into HTML you need to tell PHP your going to do this. In your code you should do something like this:

<input type="hidden" name="id" value="'.$ip.'">

That tells echo ''; to escape into PHP mode basically, and then escape back into HTML (string) mode.
IchBin™        TinyPortal

Katsulynx

Maybe I expressed myself a little bit missunderstandable.. sorry, its my fault because I only speak school-english
let's try to explain again:

I created a new page based on php, so its now no html-document any more but an .php document. It's located in the same folder as my forum and does exactly look like the rest of the forum. If you want to try it, here is the page: http://nightfox.bplaced.de/Forum/Charakteranmeldung.php [nofollow]
Now there are a lot of fields to be filled out by the user and when he submits the document with the last button, he will be redirected to the next file which adds all the information he sent to the database. But now I want the next file to send also his name and his ip to the database. So it is necessary to insert his name and his ip into a hidden field in the form which fills itself with a variable that includes his name and his ip.
<form name="Formular" action="xyz.php" method="post">
<input type="hidden" name="id" value="$ip">
<input type="hidden" name="name" value=""$name">

Now I need to get the name and ip of the user and put them into the variables ip and name. My problem is now, that the two commands $user_info['name'] and $user_info['ip'] seems not to work. However, the SSI.php is already included in my .php file:
//Path to SSI.php
require(dirname(__FILE__) . '/SSI.php');


So now I need to call the name and the ip of the current user and put them into those two variables and that is, what I am not able to do..

IchBin™

Without knowing what is in each file I cannot tell how you need to do this. It looks like your Charakteranmeldung.php file is sending the form input data to the CharakteranmeldungAbsenden.php file. Why not include SSI.php in the Charakteranmeldung.php page , and then you can add the hidden inputs to that page which you then add the name and IP to?

If you include SSI in that page and then setup the inputs like I showed you a post above the ip/name will be sent in the form, which you can then grab and do whatever you need to when the data is sent to the Charakteranmeldung.php page.

The Charakteranmeldung page should then be able to grab the name and ip from the $_POST array.
IchBin™        TinyPortal

Katsulynx

I already included SSI in my Charakteranmeldung.php, but the commands
$user_info['name'] and $user_info['ip']
cause
Parse error: syntax error, unexpected T_VARIABLE in /users/nightfox/www/Forum/Charakteranmeldung.php on line 21

line 21 is where i add those two things. I tried to only write them there as
$user_info['name']
or write them like
"$name = $user_info['name']"
or
$ip='.user_info['ip'].'
is also causing the same error.

If I would be able to get the name and the ip stored into the two variables $name and $ip, it shoult work.

IchBin™

$name = $user_info['name'];
$ip = $user_info['ip'];


If you are inside a function make sure that you are either calling the SSI.php file inside that function, or that you global $user_info at the top of your function if the include is outside the function.
IchBin™        TinyPortal

Katsulynx

it does now look like that:
require(dirname(__FILE__) . '/SSI.php');
global $name = $user_info['name'];
global $ip = $user_info['ip'];

but it also causes the Parse error in the first line beginning with global...

IchBin™

Global is only used if you are pulling a variable in from outside a function.

require(dirname(__FILE__) . '/SSI.php');
$name = $user_info['name'];
$ip = $user_info['ip'];
IchBin™        TinyPortal

Katsulynx

Oh jeah!! Finally it is working!! Thanks a thousand times!!!
I thought it should be global because I added it at the beginning of my .php file and the point where it is used is very much further down, but it seems it should not.
So in the end, it was so simple, but I failed epically...
Thanks a lot for your help!  ;D

IchBin™

No problem. Simple things often take time to learn. Once you wrap your head around it you just laugh at yourself. Makes for some good times. lol
IchBin™        TinyPortal

Advertisement: