问题
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 :)
回答1:
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.
回答2:
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.
回答3:
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!!!
来源:https://stackoverflow.com/questions/20970131/php-file-is-not-running-using-xampp