Jump to content

Hmmm... Ever felt like ending it all lol?


Recommended Posts

Could anybody please tell me where I am going wrong here???

 

I want the form to auto fill with user data for the correct user selected from the optionbox (select).. but for the life of me I can't work out what is going on.

 

<?php require_once('../Connections/timedb.php'); 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tblcustomer SET clientname=%s, hoursworked=%s, hoursleft=%s, hoursallocated=%s WHERE clientid=%s",
                       GetSQLValueString($_POST['clientname'], "text"),
                       GetSQLValueString($_POST['hoursworked'], "text"),
                       GetSQLValueString($_POST['hoursleft'], "text"),
                       GetSQLValueString($_POST['hoursallocated'], "text"),
                       GetSQLValueString($_POST['clientid'], "int"));

  mysql_select_db($database_timedb, $timedb);
  $Result1 = mysql_query($updateSQL, $timedb) or die(mysql_error());
  print 'Query Ran: '.$updateSQL.' Result: '.$Result1;
}

mysql_select_db($database_timedb, $timedb);
$query_conn = "SELECT * FROM tblcustomer";
$conn = mysql_query($query_conn, $timedb) or die(mysql_error());
$row_conn = mysql_fetch_assoc($conn);
$totalRows_conn = mysql_num_rows($conn);
?>

<?php
function hourstodecimal ($timeinhours) {
  $timeparts = explode(':', $timeinhours);
  return ($timeparts[0] + ($timeparts[1]/60));
}

function decimaltohours ($timeindecimal) {
  $hours = floor($timeindecimal);
  $minutes = str_pad( (($timeindecimal - $hours)*60), 2, '0');
  return $hours.':'.$minutes;
}

// $hourstoday = hourstodecimal($_POST['hourstoday']); 
$remintime = decimaltohours ($row_conn['hoursallocated'] - $row_conn['hoursworked']); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" id="box">
  <tr>
    <td height="346" valign="top" bgcolor="#D8E9EC"><div align="center" class="headstyle">
      <p>Customer Time Logging</p>
      <p class="contstyle">This page allows you to log your time each time you visit a customer. This will then be removed from their monthly allowance and tell you the remaining time left for their support contract. </p>
      <p class="contstyle"><?php echo $totalworked; ?></p>
    
      <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
        <table width="263" align="center">
          <tr valign="baseline">
            <td width="99" align="right" valign="middle" nowrap class="contstyle"><div align="left">Clientname:</div></td>
            <td width="106" valign="top" class="contstyle"><label>
              <div align="left">
           <select name="select">
           <?php do { ?>
           <option value="<?php echo $row_conn1['clientname']?>"> <?php echo $row_conn['clientname']?></option>
           <?php
} while ($row_conn = mysql_fetch_assoc($conn));
  $rows = mysql_num_rows($conn);
  if($rows < 10) {
      mysql_data_seek($conn, 0);
  $row_conn = mysql_fetch_assoc($conn);
  }
?>
         </select>
      </div>
              </label></td>
          </tr>

          <tr valign="baseline">
            <td align="right" valign="middle" nowrap class="contstyle"><div align="left">Job Number: </div></td>
            <td valign="middle" class="contstyle"><div align="left">
              <select name="select2">
                <?php do { ?>
                <option value="<?php echo $row_conn1['clientname']?>"> <?php echo $row_conn['clientname']?></option>
                <?php
} while ($row_conn = mysql_fetch_assoc($conn));
  $rows = mysql_num_rows($conn);
  if($rows < 10) {
      mysql_data_seek($conn, 0);
  $row_conn = mysql_fetch_assoc($conn);
  }
?>
              </select>
            </div></td>
          </tr>
          <tr valign="baseline">
            <td align="right" valign="middle" nowrap class="contstyle"><div align="left">Hours Worked:</div></td>
            <td valign="middle" class="contstyle"><div align="left">
                  <input name="hourstoday" type="text" value="00:00" size="5" maxlength="5"> 
              HH:MM </div></td>
          </tr>
          <tr valign="baseline">
            <td align="right" valign="middle" nowrap class="contstyle"><div align="left">Remaining Hours:</div></td>
            <td valign="middle" class="contstyle"><div align="left">
                  <input name="txtremhours" type="text" id="txtremhours" value="<?php echo $remintime; ?>" size="5" maxlength="5"> 
              HH:MM </div></td>
          </tr>
          <tr valign="baseline">
            <td colspan="2" align="right" valign="middle" nowrap class="contstyle"><div align="center">
              <input type="submit" value="Update record">
            </div></td>
            </tr>
        </table>
        <p>
          <input type="hidden" name="MM_update" value="form1">
          <input type="hidden" name="clientid" value="<?php echo $row_conn['clientid']; ?>">
	  <input type="hidden" name="clientname" value="<?php echo $row_conn['clientname']; ?>">
          <input type="hidden" name="hoursleft" value="<?php echo $row_conn['hoursleft']; ?>">
      <input type="hidden" name="hoursallocated" value="<?php echo $row_conn['hoursallocated']; ?>">
          <input type="hidden" name="hoursworked" value="<?php echo $row_conn['hoursworked'] +hourstodecimal($_POST['hourstoday']) ?>">
        </p>
        <p class="contstyle">This month, the customer has currently used <?php echo decimaltohours($row_conn['hoursworked']); ?> of their allocated <?php echo decimaltohours($row_conn['hoursallocated']); ?> hours.</p>
        </form>
      </div></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($conn);
?>

Link to comment
https://forums.phpfreaks.com/topic/68136-hmmm-ever-felt-like-ending-it-all-lol/
Share on other sites

eits, I think the right first step is to give your variables more meaningful names.  What is $row_conn?  What is $row_conn1?  What data does the $conn result represent?

 

Also, $row_conn changes its meaning because it is re-used in the while() loop later on.  Better to use a new variable name to avoid confusion.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.