MAMP running, PHP not
Calling a php file from a simple HTML form - e.g., - get php source code in browser as result (see below).
Figured issue is that PHP is not running on localhost (using older version of MAMP). Checked, double-checked, and upgraded to latest MAMP PRO version (2.1.4).
Still have the same problem - PHP & Apache configs look correct.
Thoughts? (guessing that first suggestion will be to ditch MAMP.)
PHP:
<?php
//Open a database connection
$con = mysqli_connect('localhost', 'root', 'root') or die( mysql_error() ); mysql_select_db($database) or die( mysql_error() );
//Declare variables for form data
$toDoItem = mysql_real_escape_string ($_POST["toDoItem"]);
$toDoDue = mysql_real_escape_string ($_POST["toDoDue"]);
$toDoOwner = mysql_real_escape_string ($_POST["toDoOwner"]);
//Query
$sql = "INSERT INTO toDo
(toDoItem, toDoDue, toDoOwner)
VALUES ($toDoItem, $toDoDue, $toDoOwner)";
$result = mysql_query($sql) or die( mysql_error() );
if($result){
echo ("<br>Data input successful.");
} else {
echo ("<br>Data input failed.");
}
//close the connection
mysql_close();
?>
Answer
Solution:
Do you get the MAMP screen when you go to localhost? I think that if you get the screen but click on PhpInfo it will also print out regular php statements.
It seems that it's because of a faulty install