PHP Form Variables

I have this form I’ve created with php to display inside an area of my site:

[php]<?php
echo "

Login

Username:
Password:

"
?>[/php]

and I’m trying to pass the information entered in the ‘username’ text field to another php file for checking against a database. The other php file is so far nothing more than:

[php]<?php
$username=$_POST[“id”];
echo “”
?>[/php]

just to make sure it’s working. So far… it’s not working. Any ideas or advice would be greatly appreciated! :smiley:

p.s. setting the form to some sort of “action=‘login.php?id=blahblah’” is not an option… no page blinking allowed.

$username=$_POST[“username”];

Your not submitting anything as $_POST[“id”]

changing the id -> username didn’t work

I’ve also tried:

$username=$_GET[“id”];

and

$username=$_GET[“username”];

but they did nothing.

Just realized u haven’t named your input fields

gave them names and still nadda… with get/post id/username

maybe it’s something in the onclick event? not sure what it’s actually doing with it all being wrapped in php like that :confused:

Hi guys,

If you want to use the onclick method to submit a form (which I don’t know why you would do that if you could do it the old fashioned way) do the following:

<input type="button" name="Submit" value="Submit" onclick="location='login.php'">

Try this and see if the code works the way you want.

Cheers!

How do you set the ticks/quotes for that inside php?

i.e.
[php]<?php
echo"

"?>[/php]

do I need to put put a junction echo in there? like so:

[php]<?php
echo"

"; ?>[/php]

I’m still figuring all this stuff out :stuck_out_tongue:

Hi again,

You would use a backslash () in your code as follows:

[php]

<?php echo " "; ?>

[/php]

This will allow you to use the double-quote inside of another double-quote.

Cheers!

Good to know ;D but using ‘location’ reloads the whole site and not just the php-form… which is bad. I got a lot more going on outside of that tiny php-form that I can’t have reloading every time someone uses an internal form.

no page blinking allowed

On the plus-side, it made an empty alert box pop up after everything disappeared. :stuck_out_tongue:

I decided to take the longer road with this:

[php]<?php
echo "

Login

*all fields are required*


Username:
Password:

"
?>[/php]

[code]function Login(username)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}

xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        document.getElementById("prodlist").innerHTML=xmlhttp.responseText;
    }
}
xmlhttp.open("GET","login.php?id="+username);
xmlhttp.send();

}[/code]

[php]<?php
$username=$_GET[“id”];
echo “$username”;
?>[/php]

It successfully spits out the username that was entered in the text field after clicking the button… but is there really no shorter way around this? Like just passing that value more directly to the other php file?

Sponsor our Newsletter | Privacy Policy | Terms of Service