Link to home
Start Free TrialLog in
Avatar of florendine
florendine

asked on

Insert Record - for Specific User

I'm sure this is very easy but i keep hitting a brick wall;

Using Dreamweaver MX2004

I have 2 tables : Athlete and performance

athlete; athlete_id, athlete_name, athlete_email, athlete_password, athlete_no
performance; log_id. athlete_id, log_date, log_event, log_perf, log_venue

So far I have created a login page that creates a session variable that holds the athlete email, I have created a update user page, change password page etc. I used the php login suit extension to do this.

I problem I am having is when I try to build a page that inserts data into the performace table. I want the page designed so when the user login's in they simply enter[log_date, log_event, log_perf, log_venue]. I don't want the athlete to enter their athlete_id every time they input a new performance.  Can the athlete_id be held in a session variable when they login and used when they enter a new performance.

The login page created the following code to create the sesion variable>
else {
            mysql_free_result($rsLogin);
            session_register("login_sac");
            $HTTP_SESSION_VARS['login_sac'] = $HTTP_POST_VARS['textfield'];
            header("Location: Index.php");


Any help would be great, this is frying my head has i'm sure the solution is easy...

Thanks in Advance


Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

so why dont to generate another session variable same as you generated with the email?
Avatar of florendine
florendine

ASKER

Sure sounds a good idea, thou how would i code the page to create the new session variable. Surly with the pervious code the session variable is created from data inputted in the textfield. I would need to retrieve the athlete_id from the database. Sorry if the answer is obvious!!!. I have included the code for the page:

<?php
// Buzz inet PHPLS01 - Login & Set Session
// Enable Session Support for page
session_start();
?>
<?php require_once('Connections/training.php'); ?>
<?php
// Buzz inet PHPLS01 - Login & Set Session - Recordset
$myUsername_rsLogin = "0";
if (isset($HTTP_POST_VARS['textfield'])) {
  $myUsername_rsLogin = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['textfield'] : addslashes($HTTP_POST_VARS['textfield']);
}
$myPassword_rsLogin = "0";
if (isset($HTTP_POST_VARS['textfield2'])) {
  $myPassword_rsLogin = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['textfield2'] : addslashes($HTTP_POST_VARS['textfield2']);
}
mysql_select_db($database_training, $training);
// Verify Login is correct
$query_rsLogin = sprintf("SELECT athlete_email, athlete_password FROM athlete WHERE athlete_email = '%s' AND athlete_password = '%s'", $myUsername_rsLogin,$myPassword_rsLogin);
$rsLogin = mysql_query($query_rsLogin, $training) or die(mysql_error());
$row_rsLogin = mysql_fetch_assoc($rsLogin);
$totalRows_rsLogin = mysql_num_rows($rsLogin);

// Buzz inet PHPLS01 - Login & Set Session - Main
if($HTTP_POST_VARS['action']=="login"){
      if($totalRows_rsLogin==0){
            $errorMessage = "Please Re-Enter Details";
            mysql_free_result($rsLogin);
      } else {
            mysql_free_result($rsLogin);
            session_register("login_sac");
            $HTTP_SESSION_VARS['login_sac'] = $HTTP_POST_VARS['textfield'];
            header("Location: Index.php");
      }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<div align="center">
  <?php echo "$errorMessage"; ?>
  <form name="form1" method="post" action="<?php echo "$PHP_SELF"; ?>">
    <table width="50%"  border="0" align="center">
      <tr>
        <td> <div align="center">User Name </div></td>
        <td><div align="center">
          <input type="text" name="textfield">
        </div></td>
      </tr>
      <tr>
        <td><div align="center">Password</div></td>
        <td><div align="center">
          <input type="text" name="textfield2">
        </div></td>
      </tr>
      <tr>
        <td><div align="center"></div></td>
        <td><div align="center">
          <input type="submit" name="Submit" value="Submit">
        </div></td>
      </tr>
    </table>
    <input name="action" type="hidden" id="action" value="login">
  </form>
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did that answer you question?
I've not tried it yet, but it does makes sense to me. Thanks
I've just inserted the sql statement into the page; However u mentioned generating the session variable, i wondered if you could elaborate on the specific code required. Thanks