Jump to content

[SOLVED] Having trouble updating mysql record


mm00re

Recommended Posts

I can see where I have the needed value in my $recnum variable however whenever I try to pass it to my update.php script the value is not coming through with the rest of the variable's I use.  I can put an echo statement anywhere in the php code and the value is shown.  Thanks in advance

 

<?php
//Grab the database login info

include('db_login.php');

// Connect to the server so we can display records for the logged in employee

$connection = mysql_connect($dbHost, $dbUser, $dbPass);

if (!$connection){ 

die ("Could not connect to the SQL server: <br />". mysql_error());

}

// Select the database

$db_select = mysql_select_db($dbname);

if (!$db_select){ 

die ("Could not select the database: <br />". mysql_error());

}

// Grab the requested user record info requested and perform the query

$dprogID = $_GET['progid'];

$query = "SELECT * FROM training WHERE dprogramID = ".$dprogID."";

$result = mysql_query($query);

$traininfo = mysql_fetch_array($result);


if (!$result){ 

die ("Could not query the database, error with results: <br />". mysql_error());

}
$num = mysql_numrows($result);
//Populate the variables 

$i=0;

while ($i < $num) {
$title=mysql_result($result,$i,"dTitle");

$provider=mysql_result($result,$i,"dProvider");

$location=mysql_result($result,$i,"dLocation");

$completed=mysql_result($result,$i,"dDateCompleted");

$completed2=date("m/d/Y");

$hours=mysql_result($result,$i,"dNumHours_hours");

$minutes=mysql_result($result,$i,"dNumHours_minutes");

$recnum=mysql_result($result,$i,"dprogramID");

$i++;

}


?>
<form action="tr-update.php" method="post">
  <p>Training Title:
    <input type="text" value="<?php echo ($title);?>" name="title" size="80" />
  </p>
  <p>Provider:
    <input type="text" value="<?php echo ($provider);?>" name="provider" size="80" />
  </p>
  Location:
  <input type="text" value="<?php echo ($location);?>" name="location" size="17" />
  <label for="dDateCompleted-l">Date Completed</label>
  <INPUT TYPE="date" NAME="date1" VALUE="<?php echo ($completed2);?>" SIZE=15>
  (<A HREF="#"

   onClick="cal.select(document.forms[0].date1,'anchor1','MM/dd/yyyy'); return false;"

   NAME="anchor1" ID="anchor1">select</A>)<br />
  <br />
  Hours:
  <input type="text" value="<?php echo ($hours);?>" maxlength="3" name="hours" size="3" />
  Minutes:
  <input type="text" value="<?php echo ($minutes);?>" maxlength="2" name="minutes" size="2" />
  <label for="dNumHours-l">Number of Hours</label>
  <select name="dNumHours_hours" id="dNumHours-l" style="width:50px;">
    <?php for ($m = 1; $m <= 40; $m++) { ?>
    <option value="<?php echo ($m+1); ?>"><?php echo $m; ?></option>
    <?php } ?>
  </select>
<?php
$recnum=$_POST["dprogID"];
$selected_minutes = $_GET['$minutes'];

echo 'Class Length:

<SELECT NAME="custom10" SIZE="1" ID="mins">
<OPTION VALUE="' . $selected_minutes . '">' . $selected_minutes . '</OPTION>
<OPTION SELECTED="SELECTED" VALUE="0" $minutes<? if ($minutes=="0"){print "selected=\"selected\"";} ?> >0 mins (0.00 hrs)</OPTION>
<OPTION VALUE="25" <? if ($minutes=="25"){print "selected=\"selected\"";} ?> >15 mins (0.25 hrs)</OPTION>
<OPTION VALUE="50" <? if ($minutes=="50"){print "selected=\"selected\"";} ?> >30 mins (0.50 hrs)</OPTION>
<OPTION VALUE="75" <? if ($minutes=="75"){print "selected=\"selected\"";} ?> >45 mins (0.75 hrs)</OPTION>";</SELECT>';
?>
  <br />
  <br />
  <div id="column_left"></div>
  <div id="column_right"></div>
  <div class="spacer" align="right"">
    <input type="submit" class="submit" value="Submit Report" action="tr-update.php?id='.dprogID."/>
    <input type="button" value="Cancel" onclick="history.go(-1)" class="submit" />
  </div>
</form>
</html>

 

The code for my update.php script is this:

 

<?php
session_start();

if(!isset($_SESSION['loggedin'])) {		// If the session 'loggedin' is NOT set forward the user back to the login form with the error set
   header('Location: /training/menu.php?error=1');
   exit();  // Otherwise show the rest of the page (admin section)
}



$username = $_COOKIE['cookiename']['username'];	// Select the username from the cookie
include('db_login.php');


$recnum = $_POST["recnum"];
$title = $_POST["title"];
$provider = $_POST["provider"];
$location = $_POST["location"];
$completed2 = $_POST["completed2"];
$hours = $_POST["hours"];
$minutes = $_POST["minutes"];



$connection = mysql_connect($dbHost, $dbUser, $dbPass);
if (!$connection)
{
echo "bad connection statement";
die ("Could not connect to the SQL server: <br />". mysql_error());
}

// Verify we have connection to the database
$db_select = mysql_select_db($dbname);
if (!$db_select){ 
echo "bad database connection";
die ("Could not select the database: <br />". mysql_error());

}

$query="UPDATE training SET dTitle='$title', dProvider='$provider', dDateCompleted='$completed2', dLocation='$location', dNumHours_hours='$hours', dNumHours_minutes='$minutes' WHERE dprogramID= '$recnum' ";

$result = mysql_query($query);

if (!$result){ 
die ("Could not query the database, error with results: <br />". mysql_error());
}

mysql_close($connection);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.