2

I am a newbie in web development and I have just installed xampp. The control panel show everything is fine. All the services are running.

I have created a database in mySQL using the phpMyAdmin and everything is fine with phpMyAdmin. I am trying to make a simple form which will make me able to add data in database table. My html form and php code are as follows. Both files are in htdocs folder:

form.html

<form action="signup.php" method="post">
Email: <input type="text" name="email"> <br>
Firstname: <input type="text" name="f_name"> <br>
Lastname: <input type="text" name="l_name"> <br>
Password: <input type="password" name="password"> <br>
Stream: <input type="text" name="stream"> <br>
<input type="submit">
</form>

</body>
</html>

signup.php:

$sql="INSERT INTO student (email,f_name,l_name,password,stream)
VALUES
  ('$_POST[email]','$_POST[f_name]','$_POST[l_name]','$_POST[password]','$_POST[stream]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

mysqli_close($con);
?>

When I click on the submit button in the form, my browser, Google Chrome, takes me to file:///C:/xampp/htdocs/signup.php and shows the contents of php script instead of running it.

If i manually enter into the address bar http://localhost/signup.php the script is executed and a record with all attributes blank is inserted into student table. So m conclusion is that php is running properly.

How to run the php script when I submit my form? Thanks :)

3
  • 2
    In your browser please make sure that your url is localhost/form.html Commented Jan 7, 2014 at 11:14
  • As an aside, using mysqli like this still opens you up to SQL injection. Consider using prepared statements. Commented Jan 7, 2014 at 11:16
  • Check Your URL in address bar Your URL should be localhost/form.html Commented Jan 7, 2014 at 11:18

3 Answers 3

6

You have to call your html file over your local Webserver http://localhost/form.html otherwise your base path is your local file like you see with file:/// and your submit URL is incorrect.

Sign up to request clarification or add additional context in comments.

Comments

1

use the full url for the form.html file as u have done for the signup.php

use this http://localhost/form.html

and it will work fine.

Comments

1

First of all, you need to pass the url https://localhost/form.html to execute your form.html file properly saved in htdocs folder otherwise upon submission only PHP script will be displayed.

About Blank entries do not run signup.php directly first run form.html. If the problem continues to check that the names of columns in the database and PHP file are same or not.

Hope this answers your question!!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.