Page 1 of 1

PHP problem with a form

Posted: Sat Jun 13, 2009 4:05 pm
by aravona
I took some of my old code and am putting it into a tester site, I'm creating a log in and have set up a form, a php file to check if the username/password exsist and a sql database.

The problem I am having is that every time I press the submit button on my form the browser, instead of moving to the php page and running its code, tries to download the file. I'm not sure if this is to do with my coding or not.

heres the form:

<form action= "Login.php" method="post">
Login:
<br />
<input name="txtusername" type="text" value="" />
<br />
<br />
<input name="txtpassword" type="password" value="" />
<br />
<br />
<input type="submit" value="Log In" />
</form>

Heres the PHP it links to:
<?php

$link = mysql_connect('localhost','root','');
mysql_select_db('gametest',$link);
$sql = "SELECT * FROM userlogin WHERE username='";
$sql = $sql . $_POST[txtusername] . "' and password='" . $_POST[txtpassword] . "';";
$result = mysql_query($sql,$link);
echo "<head><meta HTTP-EQUIV='REFRESH' content='0; url=GameTestHome.html'></head>";
?>

I just dont see why it downloads perhaps its just how long I've been staring at it? Once I get this working i can move onto securing it and make my other pages!

Thanks for any help

Aravona

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 4:38 pm
by Ollie Saunders
Try:

Code: Select all

header('Content-disposition: inline');
at the top of Login.php.

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 4:39 pm
by aravona
I've put this in, same error occurs, its still trying to download the login.php file instead of running its code :S

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 4:43 pm
by Ollie Saunders
If you download the file can you see PHP code?

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 4:50 pm
by aravona
Yes you can, opens as a notepad file.

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 4:57 pm
by Ollie Saunders
OK, what's happening then is that the PHP isn't being executed at all. You can't write any PHP to solve that problem. This is most likely to be an issue of server configuration. Perhaps your placing the file in a directory where PHP code isn't executed? If your using a hosting company consult their documentation.

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 5:03 pm
by aravona
I am just using WAMP server. I reinstalled the latest one today and it's saved in the www drive. Just realised I wasn't using local host to test. My god I'm a dumbarse, too long a day! Thanks, without you saying that wouldn't have realised.

Re: PHP problem with a form

Posted: Sat Jun 13, 2009 5:48 pm
by Ollie Saunders
Ha ha! Glad we sorted it out.