Hi I am really struggling with the second lot of code here for an 
update form. In the original insert to database page I have the 
following:



<?php require_once('Connections/CC.php'); ?>
<?php
mysql_select_db($database_CC, $CC);
$query_Recordset1 =("select *, DATE_FORMAT(thedate,'%d/%m/%Y') as 
editeddate from CC_Courses");


$Recordset1 = mysql_query($query_Recordset1, $CC) or die(mysql_error
());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$thedate=$_POST['year'].'-'.$_POST['sd_month'].'-'.$_POST['dt'];




?>
<html><head>
<title>Course  Insert Record</title><meta http-equiv="Content-Type" 
content="text/html; charset=iso-8859-1">
<link href="Tasks.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args
[i+1]+"'");
}
//-->
</script>
</head>
<body><Div ID ="content">


<?php
$thedate=$_POST['year'].'-'.$_POST['sd_month'].'-'.$_POST['dt'];

$Course_Category=$_POST['Course_Category'];
$Course_Name=$_POST['Course_Name'];
$Course_Location=$_POST['Course_Location'];
$dt=$_POST['dt'];
$sd_month=$_POST['sd_month'];
$year=$_POST['year'];
$Day_Of_Week=$_POST['Day_Of_Week'];
$Start_Time=$_POST['Start_Time'];
$Finish_Time=$_POST['Finish_Time'];
$Course_Length=$_POST['Course_Length'];
$Qualification_Achieved=$_POST['Qualification_Achieved'];
$Course_Description=$_POST['Course_Description'];
$Tutor=$_POST['Tutor'];
$Previous_Experience_Needed=$_POST['Previous_Experience_Needed'];
$Spaces_Available=$_POST['Spaces_Available'];

$result=mysql_query("INSERT INTO CC_Courses (Course_Category, 
Course_Name, Course_Location, Day_Of_Week, Start_Time, Finish_Time, 
Course_Length, Qualification_Achieved, Course_Description, Tutor, 
Previous_Experience_Needed, Spaces_Available, dt, sd_month, year, 
thedate, tdate) VALUES 
('$Course_Category','$Course_Name','$Course_Location','$Day_Of_Week',
'$Start_Time','$Finish_Time','$Course_Length','$Qualification_Achieve
d','$Course_Description','$Tutor','$Previous_Experience_Needed','$Spa
ces_Available','$dt','$sd_month','$year','$thedate',NOW())")or die
("Insert Error: ".mysql_error());

print "The course has been added to the database \n";
?>   

</Div></Div> 
<form name="form1" method="post" action="">
  <input name="button" type="button" onClick="MM_goToURL
('parent','courses71509878.php');return document.MM_returnValue" 
value="View Courses">
  <input type="submit" onClick="MM_goToURL
('parent','Course_insert_form.php');return document.MM_returnValue" 
value="Add Another Course">
</form>
 </body>
</html>
<?php
mysql_free_result($Recordset1);
?>



The bit that says $thedate=$_POST['year'].'-'.$_POST['sd_month'].'-
'.$_POST['dt'];


Basically posts the day, month and year as a string into a column in 
the database called thedate and I can then format it to come out Uk 
style.

However I want to do the same when I update the records but no 
matter where I try to put it into the update form page( below) it 
just doesnt work! Is there some way I can add it into the Update 
statement? as in update tbl set dt,month,year as thedate?








<?php require_once('Connections/CC.php'); ?>
<?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 CC_Courses SET Course_Name=%s, 
Course_Category=%s, Course_Location=%s, dt=%s, sd_month=%s, year=%
s,Day_Of_Week=%s, Start_Time=%s, Finish_Time=%s, Course_Length=%s, 
Qualification_Achieved=%s, Course_Description=%s, Tutor=%s, 
Previous_Experience_Needed=%s, Spaces_Available=%s WHERE Course_ID=%
s",
                       GetSQLValueString($_POST
['Course_Name'], "text"),
                       GetSQLValueString($_POST
['Course_Category'], "text"),
                       GetSQLValueString($_POST
['Course_Location'], "text"),
                       GetSQLValueString($_POST['dt'], "text"),
                       GetSQLValueString($_POST['sd_month'], "int"),
                       GetSQLValueString($_POST['year'], "text"),

                       GetSQLValueString($_POST
['Day_Of_Week'], "text"),
                       GetSQLValueString($_POST
['Start_Time'], "text"),
                       
                       
                       GetSQLValueString($_POST
['Finish_Time'], "text"),
                       GetSQLValueString($_POST
['Course_Length'], "text"),

                       GetSQLValueString($_POST
['Qualification_Achieved'], "text"),             
                       GetSQLValueString($_POST
['Course_Description'], "text"),             
                       GetSQLValueString($_POST
['Tutor'], "text"),             
                       GetSQLValueString($_POST
['Previous_Experience_Needed'], "text"),             
                       GetSQLValueString($_POST
['Places_Available'], "text"),  
                       GetSQLValueString($_POST
['Course_ID'], "int"));

  mysql_select_db($database_CC, $CC);
  $Result1 = mysql_query($updateSQL, $CC) or die(mysql_error());

  $updateGoTo = "courses71509878.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_RecordsetUpdate = "1";
if (isset($_GET['Course_ID'])) {
  $colname_RecordsetUpdate = (get_magic_quotes_gpc()) ? $_GET
['Course_ID'] : addslashes($_GET['Course_ID']);
}
mysql_select_db($database_CC, $CC);
$query_RecordsetUpdate = sprintf("SELECT * FROM CC_Courses WHERE 
Course_ID = %s", $colname_RecordsetUpdate);
$RecordsetUpdate = mysql_query($query_RecordsetUpdate, $CC) or die
(mysql_error());
$row_RecordsetUpdate = mysql_fetch_assoc($RecordsetUpdate);
$totalRows_RecordsetUpdate = mysql_num_rows($RecordsetUpdate);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<title>Update Course</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1">
<link href="admin.css" rel="stylesheet" type="text/css">
</head>

<body><p>&nbsp;</p>
<p>&nbsp;</p>
<h4>North Somerset Education and Training Consortium  - Update 
Course Information </h4>
<form action="<?php echo $editFormAction; ?>" method="POST" 
name="form1" onSubmit="MM_validateForm('Course_Name','','R');return 
document.MM_returnValue">
  <tr>
    <td> </tr><p><br></p>
    
    
    
  <table width="70%" border="1" align="right">
  
  
  
    <tr>
      <td width="300">Course Name:</td>
      <td width="420"><input name=Course_Name type=text value="<?php 
echo $row_RecordsetUpdate['Course_Name']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
     <tr>
      <td>Course Category:</td>
      <td><input name=Course_Category type=text value="<?php echo 
$row_RecordsetUpdate['Course_Category']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Course Location:</td>
      <td><input name=Course_Location type=text value="<?php echo 
$row_RecordsetUpdate['Course_Location']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Day:</td>
      <td><input name=dt type=text value="<?php echo 
$row_RecordsetUpdate['dt']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
       <tr>
      <td>Month:</td>
      <td><input name=sd_month type=text value="<?php echo 
$row_RecordsetUpdate['sd_month']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
       <tr>
      <td>Year:</td>
      <td><input name=year type=text value="<?php echo 
$row_RecordsetUpdate['year']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
      
      
      
      <tr>
      <td>Start Time:</td>
      <td><input name=Day_Of_Week type=text value="<?php echo 
$row_RecordsetUpdate['Day_Of_Week']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Start Time:</td>
      <td><input name=Start_Time type=text value="<?php echo 
$row_RecordsetUpdate['Start_Time']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Finish Time:</td>
      <td><input name=Finish_Time type=text value="<?php echo 
$row_RecordsetUpdate['Finish_Time']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Course Length:</td>
      <td><input name=Course_Length type=text value="<?php echo 
$row_RecordsetUpdate['Course_Length']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Qualification_Achieved (If Applicable):</td>
      <td><input name=Qualification_Achieved type=text value="<?php 
echo $row_RecordsetUpdate['Qualification_Achieved']; ?>" 
size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
     <tr>
      <td>Course_Description:</td>
      <td><input name=Course_Description type=text value="<?php echo 
$row_RecordsetUpdate['Course_Description']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Tutor:</td>
      <td><input name=Tutor type=text value="<?php echo 
$row_RecordsetUpdate['Tutor']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Previous_Experience_Needed(If Applicable):</td>
      <td><input name=Previous_Experience_Needed type=text value="<?
php echo $row_RecordsetUpdate['Previous_Experience_Needed']; ?>" 
size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Places Available:</td>
      <td><input name=Places_Available type=text value="<?php echo 
$row_RecordsetUpdate['Places_Available']; ?>" size=70></td>
    </tr>
    <tr>
      <td><br></td>
      <td> <p>    <input name="Course_ID" type="hidden" 
id="Course_ID" value="<?php echo $row_RecordsetUpdate['Course_ID']; ?
>">
    <input name="Submit" type="submit" onClick="MM_validateForm
('Course_Name','','R','Course_Category','','R','thedate','','R');retu
rn document.MM_returnValue" value="Update Course Record">
  </p>
    <input type="hidden" name="MM_update" value="form1"></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>




</body>
</html>
<?php
mysql_free_result($RecordsetUpdate);
?>



Thank you





The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to