I am building a website form in HTML that I want to gather information from users, and store it in MySQL. However, when I submit the form after entering the information, the PHP script is not executed. It simply displays the PHP script in raw form. In a browser, it downloads the PHP file.
At first, I was lead to believe that this was an issue with my MySQL, PHP, Apache configuration, but after following this step by step, I still cannot execute the PHP script.
My form’s header looks like so:
<form id="form-settings" method="post" action="file.php">
file.php being the script I want to execute upon submission.
Here is my PHP script:
<?php
error_reporting(E_ALL);
$link = mysql_connect("localhost","username","password");
if (!$link)
{
die('Not connected : ' . mysql_error());
}
mysql_select_db("mysql", $link) or die("Unable to select database");
$var1=$_POST['var1'];
$var2=$_POST['var2'];
$var3=$_POST['var3'];
$var4=$_POST['var4'];
$var5=$_POST['var5'];
$query = "INSERT INTO table VALUES ('','$var1','$var2','$var3','$var4','$var5')";
mysql_query($query);
mysql_close($link); ?>
I can execute PHP files from the Terminal fine. I can query my MySQL table and enter info into it, but when I try to run it via the HTML form, it doesn’t work. The Vars are values pulled form the HTML form. Any advice would be greatly appreciated. Obviously, the php is not being recognized, but where does this issue arise from?
(i would post this as a comment, but i can’t because I’ve got too little karma…)
Have a look at the logfiles, especially the error log files. They are probably in /var/log/apache2 or something. See if there is something wrong?
Is your phpinfo()-script in the same directory as the other script? Are you accessing the script with the same hostname? (127.0.0.1 vs. localhost, for example?)