Sorry if this is not a PHP question directly. As stated in my previous post I have created a form and wish to store the values taken from this and store them in the corresponding sections of a database. The form appears to work and I have created a database called “work_stats” with a single table “daily_stats” using phpmyadmin through MAMP.
Here is the code, the form appears to function correctly but the records do not appear and I receive no error messages. I have confirmed the Mysql server is running in MAMP.
<?php
include ('Applications/MAMP/htdocs/mysqli_connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Work Statistics Form</title>
<style type="text/css" title="text/css" media="all">
label {
font-weight: bold;
color: #300ACC;
}
</style>
</head>
<body>
<!-- Script 2.1 - form.html -->
<form action="index.php" method = "post">
<fieldset><legend>Please enter information in the form below: </legend>
<p><label>Date: <input type="date" name="date"/></label></p>
<p><label>Clinic: <br><input type="radio" name="clinic" value ="Durham"/> Durham <br><input type="radio" name="clinic" value ="Newcastle"/> Newcastle <br><input type="radio" name="clinic" value ="Sunderland"/> Sunderland <br><input type="radio" name="clinic" value ="Ashington"/> Ashington <br><input type="radio" name="clinic" value ="Hartlepool"/> Hartlepool <br><input type="radio" name="clinic" value ="Bishop"/> Bishop <br><input type="radio" name="clinic" value ="Stockton"/> Stockton<br><input type="radio" name="clinic" value ="Middlesborough"/> Middlesborough <br><input type="radio" name="clinic" value ="Other"/> Other</p>
<p><label>Google Miles: <input type="number" name="c_mileage" min="0" max="500"/></label></p>
<p><label>Actual Miles: <input type="number" name="a_mileage" min="0" max="500"/></label></p>
<p><label>Appointments: <input type="number" name="appointments" min="0" max="7" /></label></p>
<p><label>Comments: <textarea name="comments" rows="3" cols="40"></textarea></label></p>
</fieldset>
<p align="center"><input type="submit" name="submit" value="Submit" /></p>
</form>
<?php
if (isset ($_POST[submit])){
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'root');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'work_stats');
// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die ('Could not connect to MySQL: ' . mysqli_connect_error() );
mysqli_select_db("work_stats", $dbc);
$sql = "INSERT INTO daly_stats (date,clinic,c_mileage,a_mileage,appointments,comments) VALUES ('$_POST[date]','$_POST[clinic]','$_POST[g_mileage]','$_POST[a_mileage]','$_POST[appointments]','$_POST[comments]')";
mysqli_query($sql, $dbc);
mysqli_close($dbc);
}
?>
</body>
</html>
Mysql connection part:
<?php
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'root');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'work_stats');
// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die ('Could not connect to MySQL: ' . mysqli_connect_error() );
?>
I tried changing all instances of mysqli to mysql and moved the connection code into the main page to test but this had no effect.