Page 1 of 1
$_GET question
Posted: Fri Nov 06, 2009 2:20 pm
by Colwell
I have a form that you complete
<form action="welcome.php" method="get">
Username<input type="text" name="username" />
Password<input type="text" name="pass" />
Email<input type="text" name="email" />
<input type="Submit" />
Then it passes all this stuff to the next page where it is put into a sentence, (the other stuff is put into the database)
Now I was wondering, how can I put the $user variable into the address of home.php so that I can $_GET it again.
Re: $_GET question
Posted: Fri Nov 06, 2009 2:22 pm
by VladSun
Put in in the query string for home.php anchor: home.php?name=$NAME
Or you could store it into the $_SESSION variable which I think is better
Re: $_GET question
Posted: Fri Nov 06, 2009 2:36 pm
by Colwell
Ok, I am new to this so, I tried
and I didn't come close. I'm guessing your link is inside the <?php ?> brackets?
Anyways, could you briefly explain how to use the $_SESSION method?
Re: $_GET question
Posted: Fri Nov 06, 2009 2:43 pm
by VladSun
Colwell wrote:Ok, I am new to this so, I tried
and I didn't come close.
It's exaclty how it should be done ... I don't know what went wrong ...
Colwell wrote:Anyways, could you briefly explain how to use the $_SESSION method?
Hm.... I thought you are familiar with working with sessions - it seems you are building a login page.
Take a look at the examples in the manual:
http://php.net/manual/en/function.session-start.php
Re: $_GET question
Posted: Fri Nov 06, 2009 3:23 pm
by flying_circus
VladSun wrote:Colwell wrote:Ok, I am new to this so, I tried
and I didn't come close.
It's exaclty how it should be done ... I don't know what went wrong ...
Perhaps a PHP Notice because $_GET['username'] was not set?
Re: $_GET question
Posted: Sat Nov 07, 2009 5:01 pm
by Colwell
OK, so I have
session_start();
In the header and
$user=$_GET["username"];
$_SESSION['username']=$user;
on the page where I already have the information to $_GET in the address bar.Then on the next page I have
echo $_SESSION['username'];
and I don't have anything displayed, is this just a syntax error?
Re: $_GET question
Posted: Sat Nov 07, 2009 6:14 pm
by Colwell
This is really strange actually, I'm not sure if my header is working. It does but it doesn't. It contains
<?php
session_start();
?>
<html>
<body>
<?php //connection junk:(
$con = mysql_connect("localhost:3306","colwell_user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("colwell_db", $con);
//connection junk:)
echo "The header is here!!";
?>
and it connects to the database and identifies the code as html but won't display the echoed bit and I don't think it is starting the session. I include it on the required pages using
include("header.php");
Re: $_GET question
Posted: Sat Nov 07, 2009 9:18 pm
by Daniel03155
Hello,
Code: Select all
session_start();
/* Html stuff */
$connection = mysql_connect("localhost", "user", "pass") or die(mysql_error());
$select_db = mysql_select_db("Database") or die(mysql_error());
echo "Works.";
Btw the second argument to mysql_select_db is optional. The code above works perfectly, it's basically the same as yours though a little cleaner. You can check if the session started or not by going to your browser's options and checking the cookies.(in FF's case is "remove individual cookies"). Search for localhost.