如何在登录日期时间表中存储数据?

时间:2015-11-07 13:26:55

标签: php mysql

我的项目是为糖尿病患者创建一本期刊。首先,当用户登录时,将捕获时间戳并将其插入数据库。然后当用户转到下一页插入血糖数据时,数据不能插入与时间戳(登录时间)相同的表中。我使用了会话,但它在血糖页上显示错误。所以这是我的编码: -

<?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>

0 个答案:

没有答案