0

I am trying to create a sign up website (for practice) using sql and php. The server I am using is xampp who i have tested using http://localhost/info.php and it returns the php info as requsted. I have saved all my files in the htdocs folder within the xampp folder. But when i run my code, everytime the form is submitted, it shows the php source code. I am fairly new to this, please help login.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<form action="signup.php" method="POST">
<input type="text" name="first" placeholder="Firstname"><br />
<input type="text" name="last" placeholder="Lastname"><br />
<input type="text" name="uid" placeholder="Username"><br />
<input type="password" name="pwd" placeholder="Password"><br />
<button type="submit">SIGN UP</button>
</form>

</body>
</html>
signup.php:

<?php
 include 'dbh.php';
 
 $first = $_POST['first'];
 $last = $_POST['last'];
 $uid = $_POST['uid'];
 $pid = $_POST['pwd'];

    echo $first;
    echo $last;
    echo $uid;
    echo $pid;
?>

dbh.php:

<?php
 $conn = mysqli_connect("localhost", "root", "password", "login");
 
 if(!$conn){
  die("Connection failed: ".mysqli_connect_error());
 }
?>
Liam Sperry
  • 318
  • 2
  • 9
  • _But when i run my code_ - do you mind telling how exactly you invoked that program? Is it the case that the program was run from the browser using directory path and not the `localhost` address? – Dhruv Saxena Apr 06 '17 at 19:55
  • @Dhruv Saxena i open up the html file in the folder, the url used is file:///C:/xampp/htdocs/login.html . I just tried using local host and when i submitted the form instead of displaying the php file, it sent me to the xampp dashboard – Liam Sperry Apr 06 '17 at 20:00
  • Looks like this should do the trick - http://stackoverflow.com/q/312881/2298301. Assuming your `login.html` sits right in the `htdocs` folder, the path to invoke this file would be: `http://localhost/login.html`. However, it'd be advisable to create your own project directory and access it accordingly - `http://localhost/project123/login.html`. If you go to path `http://localhost/project123`, the server will first look for any `index.html` file and then for `index.php`. If neither is found, you'll be presented with a list of files there. So it's always a good idea to have an `index.php` file. – Dhruv Saxena Apr 06 '17 at 20:07
  • Thank you so much! It works! – Liam Sperry Apr 06 '17 at 20:18

0 Answers0