topical media & game development
basic-mysql-17-PHPApp-edit.php / php
<?
*****************************************************************************
Author: Geoff Moes and Robert Sheldon
Project: Begining MySQL - Chapter 17
Module: edit.php
Date: 12/10/04
Description:
This page lists the individual record. It is called from the main page.
If the page is called with an "add" command, it creates a blank record
and populates it with default values. If it is called with an "edit"
command, it displays an existing record.
*****************************************************************************
?>
<?
// Connect to server or return an error
link);
// Initialize an error-related variable
_POST["command"]))
_POST["command"];
if(isset(transactionId = _POST["date_due"]))
_POST["date_due"];
if(isset(orderId = _POST["dvd_id"]))
_POST["dvd_id"];
if(isset(dateOut = _POST["date_in"]))
_POST["date_in"];
// Processes the save and savenew commands
if((strcmp("save", command) == 0))
{
// Check for missing parameters
if(error .= "Please select an \"Order\"<br>";
if(error .= "Please select a \"DVD\"<br>";
if((dateOut) == 0))
dateDue == null) || (strlen(error .= "Please enter a \"Date Due\" Value<br>";
if(strlen(dateOut != null)
dateOut, 6, 4)."-".substr(dateOut, 3, 2);
if(dateDue = substr(dateDue, 0, 2)."-".substr(dateIn != null)
dateIn, 6, 4)."-".substr(dateIn, 3, 2);
else
command) == 0)
{
// Run the update in update.php
include <update.php>;
}
else
{
// Run the insert in insert.php
include <insert.php>;
}
// Redirect the application to the listing page
header("Location: index.php");
exit;
}
}
else
{
// If it is a new record, initialize the variables to default values
if(strcmp("add", transactionId = 0;
dvdId = 0;
dateDue = date("m-d-Y", time() + 3*24*60*60);
transactionId != null)
{
// Build query from transactionId value passed down from form
transactionId'";
// Execute query
selectSql, result)
die("Invalid query: " . mysql_error(). "<br>".row = mysql_fetch_array(orderId = dvdId = dateOut = dateDue = dateIn = dateOut != null)
dateOut, 5, 2)."-".substr(dateOut, 0, 4);
else
dateDue != null)
dateDue, 5, 2)."-".substr(dateDue, 0, 4);
else
dateIn != "0000-00-00")
dateIn, 5, 2)."-".substr(dateIn, 0, 4);
else
transactionId);?>" size="50">
<p></p>
<table cellspacing="0" cellPadding="0" width="619" border="0">
<tr>
<td>
<table height="20" cellspacing="0" cellPadding="0" width="619" bgcolor="#bed8e1" border="0">
<tr align=left>
<td valign="bottom" width="400" class="title">
DVD Transaction
</td>
<td align="right" width="219" class="title"> </td>
</tr>
</table>
<br>
<?if(strlen(error);?>
</td>
</tr>
</table>
<?}?>
<table cellspacing="2" cellPadding="2" width="619" border="0">
<tr>
<td width="250" class="heading">Order</td>
<td class="item">
<select name="order_id">
<option value="-1">Select Order</option>
<?
// Retrieve data to populate drop-down list
result = mysql_query(link);
if (!selectSql);
// Loop through the results
while(result))
{
// Assign returned values to the variables
row["OrderID"];
row["CustFN"];
row["CustLN"];
// Format the data for display
custFirstName != null)
custFirstName . " ";
if(customerName .= orderId1 != orderId1)?>"><?printf(customerName);?></option>
<?
}
else
{
?>
<option selected value="<?printf(orderId1)?> - <?printf(selectSql = "SELECT DVDID, DVDName FROM DVDs ORDER BY DVDName";
selectSql, result)
die("Invalid query: " . mysql_error(). "<br>".row = mysql_fetch_array(dvdId1 = dvdName = dvdName == null)
dvdId1 != dvdId1);?>"><?printf(dvdId1);?>"><?printf(dateOut);?>" size="50">
</td>
</tr>
<tr>
<td class="heading">Date Due</td>
<td class="item">
<input type="text" name="date_due" value="<?printf(command) != 0) && (strcmp("savenew", dateIn);?>" size="50">
</td>
</tr>
<?}?>
<tr>
<td colspan="2" class="item" align="center">
<table cellspacing="2" cellPadding="2" width="619" border="0">
<tr>
<td align="center">
<?if((strcmp("add", command) == 0)){?>
<input type="button" value="Save" class="add" onclick="doSave(this, 'savenew')">
<?}else{?>
<input type="button" value="Save" class="add" onclick="doSave(this, 'save')">
<?}?>
</td>
<td align="center">
<input type="button" value="Cancel" class="add" onclick="doCancel(this)">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
// Close connection
mysql_close(
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.