1

I have a file signupform.html which has the following code:

<!DOCTYPE html>
<html>
<body>
<form action = "signup.php" method = "post">
     USERNAME:<input type="text" name="uname"><br/>
    PASSWORD:<input type="password" name="pswd"><br/>
    <input type ="submit">
</form>
</body>
</html>

Note that the action attribute of form calls signup.php

And the file signup.php has this code:

<?php
require('db.php');

$username = mysqli_real_escape_string($myConn,$_POST['uname']);
$password = mysqli_real_escape_string($myConn,$_POST['pswd']);

$query= 'SELECT COUNT(*) FROM $database WHERE USERNAME=$username;';
$result=mysqli_query($myConn,$query);
$array=mysqli_fetch_array($result);
if(!$query)
    echo 'FAILED:'.mysqli_error();
if($array[0]==1)
    echo 'A user with this username already exists! Please select a different username.';

else if($array[0]==0)
    {
        mysqli_query('INSERT INTO $database VALUES ($username , $password)');
        echo 'Congratulations! You have been signed up successfully.';
    }

?> 

db.php has this code:

<?php
$host = 'localhost';
$uname='root';
$pswd='';
$myDB='signup';
$myConn = new mysqli($host,$uname,$pswd);

$database = mysqli_select_db($myConn,$myDB);

?>

Now, the problem I am facing is that when I open signupform.html and enter the username and password, the signup.php file is downloaded. Why is that happening?

  • 2
    is php installed on your server?? have you tried in multiple browsers??? btw are you accessing `signupform.html` from localhost or directly via double click?? – Ali Arshad Mar 16 '15 at 18:20
  • I am a beginner so I am not really sure. I use apache2 server. How do I confirm if I have php installed on my server? – user2983071 Mar 16 '15 at 18:26
  • do you have windows or Linux on your server?? – Ali Arshad Mar 16 '15 at 18:27
  • Umm, I double clicked it. Does that make any difference? – user2983071 Mar 16 '15 at 18:27
  • I have linux on my server. – user2983071 Mar 16 '15 at 18:28
  • make a file lets say `php.php`, add this code `` access it from browser... what does it show?? – Ali Arshad Mar 16 '15 at 18:30
  • What do you mean by getting downloaded? – Gokigooooks Mar 16 '15 at 18:31
  • I did what you said with php.php and opened it with chrome. It showed a whole bunch of information including php version. – user2983071 Mar 16 '15 at 18:42
  • @Gokigooooks It gets downloaded like a normal text file in the web browser. Just like you download a file from some website! – user2983071 Mar 16 '15 at 18:43
  • Hmmm I dont see any part of the code you've given which prompts a download of a file. – Gokigooooks Mar 16 '15 at 18:44
  • try rebooting your pc and your wamp/xamp – Gokigooooks Mar 16 '15 at 18:45
  • @Gokigooooks Exacty! That is where my problem lies. – user2983071 Mar 16 '15 at 18:45
  • Btw, I use apache2 server. I tries restarting it but it won't work! – user2983071 Mar 16 '15 at 18:49
  • **WARNING**: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong, like how you're using the ancient, deprecated `mysql_query` interface here and are storing **plaintext passwords** which is completely unacceptable. Please, do not write your own authentication system when any modern [development framework](http://codegeekz.com/best-php-frameworks-for-developers/) like [Laravel](http://laravel.com/) comes with a robust [authentication system](http://laravel.com/docs/security) built-in. See [PHP the Right Way](http://www.phptherightway.com/) – tadman Mar 16 '15 at 18:55

2 Answers2

0

If you are running XAMPP/WAMPP, Have you been placed the file signup.html in your htdocs directory ? If not do place under htdocs/signupform.html

0

I was searching for similar problems to yours and I found this.

Apache is downloading php files instead of displaying them

The solution proposed may be too technichal.A more simple solution would be to uninstall your wamp/xamp and redownload to get a new set of php files.

Community
  • 1
  • 1
Gokigooooks
  • 794
  • 10
  • 20