0

Hi I am trying to create a log system were users can log activities, once they are logged in their username is held in a session. My problem is I want them to be able to create a new log by filling out a form but I don't want them to have to enter their user name every time rather grab the username from the session and pop it into the insert statement. Here is the code I would greatly appreciate any help asap as it is for a project with looming deadline. Cheers.

<?php
session_start();
if(!session_is_registered("myusername")){
header("location:main_login.php");
}

include 'topmembers.php';
?>

<div id="page" class="container">
<!--First Post-->		<div id="content">
			<div class="post">

<?php

$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("newcastle", $con);

$sql="INSERT INTO log (logid, username, logdate, type, totaltime_mins, total_distance, notes)

VALUES (Null,'".$_SESSION['myusername']."',$_POST[logdate]','$_POST[type]','$_POST[totaltime_mins]', '$_POST[total_distance]','$_POST[notes]')";

echo .$_SESSION['myusername']

?> 

<?php


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Log Saved";


mysql_close($con)
?> 

</div>
			
			</div>
<?php
include 'websiteend.php';
?>

It simply returns a blank page

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by somedude3488
0

You can't use session_is_registered() with the $_SESSION array. They don't work nicely together.

You might also want to look at mysql_real_escape_string to prevent sql injection.

Edited by somedude3488: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.