my project is to create a journal for diabetic patients. First, when the user logging in, the timestamp will be captured and inserted into the database. And then when the user go to next page to insert blood glucose data, the data cannot be inserted into the same table as the timestamp (login time) . I used sessions but it showed error on the blood glucose page. So here is my coding :-
<?php
// Start the session
session_start();
if (isset($_SESSION['time_id'])) {
include 'connection.php';
$time_id = $_SESSION['time_id'];
$query = "SELECT * FROM journal WHERE time_id = '$time_id'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
}
$bloodglucose = $_POST['bloodglucose'];
$time_id = $_SESSION['time_id'];
$bloodpressure = 0.0;
$qry = mysql_query("INSERT INTO journal VALUES ('" . $time_id . "','" . $row2['user_id'] . "','" . $bloodglucose . "','" . $bloodpressure . "')");
if ($qry) {
echo "<script language='javascript'>alert('Your data has successfully recorded');</script>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/prototype3/userhome.php\">";
} else {
echo "Sorry, your data failed to be added to the database<br />";
}
?>
<th width="56%">
<br>
<div class="col-sm-8">
<div class="input-group">
<form action="bloodglucoseEntry.php" method="post" style="margin:0">
<table>
<tr>
<td> </td><td>Blood glucose level (mg/dl) </td><td>:</td>
<td><input type="text" class="form-control" name="bloodglucose" id="bloodglucose" size="30" maxlength="30" value=""/></td>
</tr>
</table>
</div>
</div>
</p><p><br><br><br>
<p align="right">
<input type="submit" name="submit" class="btn btn-info" value="Add" />
<button type="button" class="btn btn-danger">Cancel</button></a>