0

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>&nbsp;</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>
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
chichi
  • 1
  • 1
  • Welcome. It would be useful if you explained what the exact error is that you are receiving, and what you have done to debug it so far. – wwkudu Nov 07 '15 at 13:41
  • Im sorry, i'm new to this. My error is :- Notice: Undefined index: bloodglucose in C:\xampp\htdocs\prototype3\bloodglucoseEntry.php on line 235 Notice: Undefined variable: time_id in C:\xampp\htdocs\prototype3\bloodglucoseEntry.php on line 239 Notice: Undefined variable: row2 in C:\xampp\htdocs\prototype3\bloodglucoseEntry.php on line 239 Sorry, your data failed to be added to the database – chichi Nov 07 '15 at 13:51
  • No problem. Edit your question with the details of the error. – wwkudu Nov 07 '15 at 13:52
  • Notice: Undefined index: bloodglucose in C:\xampp\htdocs\prototype3\bloodglucoseEntry.php on line 235 //blood glucose has been retrieved from the form using $_POST there is still error Notice: Undefined variable: time_id in C:\xampp\htdocs\prototype3\bloodglucoseEntry.php on line 239 //time_id has the sameattribute name as in the Journal database table but it still show error Notice: Undefined variable: row2 in C:\xampp\htdocs\prototype3\bloodglucoseEntry.php on line 239 Sorry, your data failed to be added to the database – chichi Nov 07 '15 at 13:55
  • 1
    So, it looks like it is complaining that "bloodglucose" doesn't exist in the $_POST. [This question](http://stackoverflow.com/questions/10809937/undefined-index-with-post) explains a similar problem - at least you need to get past that problem first it seems. – wwkudu Nov 07 '15 at 14:04

0 Answers0