Forums

PHP

This topic is locked

Insert/Update Server behavior issues

Posted 10 Feb 2007 22:39:36
1
has voted
10 Feb 2007 22:39:36 Toby Donovan posted:
I hope someone can help because I can't find anything online that is helping me with this problem. I can't get the Dreamweaver controls to work when coding a PHP insert or update record page. It looks like it creates the code correctly but when I put them out on my webserver and then fill out the form and click submit the page submits and tries to use a URL string of (null)/admin/edit_class.php?SchedulePrimaryID=1 where edit_class.php is the form page not the page I told it to redirect to. I don't know why the (null) value keeps getting inserted into the string either. The browser obviously can't find this URL so gives a page cannot be displayed screen and nothing get's inserted or updated in the mySQL database.

Any help would be greatly appreciated. This problem is driving me crazy because I want to save time not having to hand code things. Below is a Update page using the Dreamweaver controls that has the problem.

<?php require_once('../Connections/DS911DB.php'); ?><?php
if (!function_exists("GetSQLValueString") {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string" ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "Schedule") {
$updateSQL = sprintf("UPDATE tblSchedule SET ScheduleID=%s, ScheduleCourseID=%s, ScheduleCourseType=%s, ScheduleLocationID=%s, ScheduleResourceID=%s, ScheduleMonday=%s, ScheduleTuesday=%s, ScheduleWednesday=%s, ScheduleThursday=%s, ScheduleFriday=%s, ScheduleSaturday=%s, ScheduleSunday=%s, ScheduleStartTime=%s, ScheduleEndTime=%s, ScheduleStartDate=%s, ScheduleEndDate=%s, ScheduleOnlineSeats=%s WHERE SchedulePrimaryID=%s",
GetSQLValueString($_POST['ScheduleID'], "text",
GetSQLValueString($_POST['ScheduleCourseID'], "int",
GetSQLValueString($_POST['ScheduleCourseType'], "text",
GetSQLValueString($_POST['ScheduleLocationID'], "int",
GetSQLValueString($_POST['ScheduleResourceID'], "int",
GetSQLValueString(isset($_POST['ScheduleMonday']) ? "true" : "", "defined","1","0",
GetSQLValueString(isset($_POST['ScheduleTuesday']) ? "true" : "", "defined","1","0",
GetSQLValueString(isset($_POST['ScheduleWednesday']) ? "true" : "", "defined","1","0",
GetSQLValueString(isset($_POST['ScheduleThursday']) ? "true" : "", "defined","1","0",
GetSQLValueString(isset($_POST['ScheduleFriday']) ? "true" : "", "defined","1","0",
GetSQLValueString(isset($_POST['ScheduleSaturday']) ? "true" : "", "defined","'Y'","'N'",
GetSQLValueString(isset($_POST['ScheduleSunday']) ? "true" : "", "defined","1","0",
GetSQLValueString($_POST['ScheduleStartTime'], "date",
GetSQLValueString($_POST['ScheduleEndTime'], "date",
GetSQLValueString($_POST['ScheduleStartDate'], "date",
GetSQLValueString($_POST['ScheduleEndDate'], "date",
GetSQLValueString($_POST['ScheduleOnlineSeats'], "int",
GetSQLValueString($_POST['PrimaryID'], "int");

mysql_select_db($database_DS911DB, $DS911DB);
$Result1 = mysql_query($updateSQL, $DS911DB) or die(mysql_error());

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

if (!function_exists("GetSQLValueString") {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string" ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

$class_rsSchedule = "-1";
if (isset($_GET['SchedulePrimaryID'])) {
$class_rsSchedule = $_GET['SchedulePrimaryID'];
}
mysql_select_db($database_DS911DB, $DS911DB);
$query_rsSchedule = sprintf("SELECT * FROM tblSchedule WHERE tblSchedule.SchedulePrimaryID = %s", GetSQLValueString($class_rsSchedule, "int");
$rsSchedule = mysql_query($query_rsSchedule, $DS911DB) or die(mysql_error());
$row_rsSchedule = mysql_fetch_assoc($rsSchedule);
$totalRows_rsSchedule = mysql_num_rows($rsSchedule);

mysql_select_db($database_DS911DB, $DS911DB);
$query_rsLocations = "SELECT * FROM tblLocations WHERE LocationType = 'P' ORDER BY LocationName";
$rsLocations = mysql_query($query_rsLocations, $DS911DB) or die(mysql_error());
$row_rsLocations = mysql_fetch_assoc($rsLocations);
$totalRows_rsLocations = mysql_num_rows($rsLocations);

mysql_select_db($database_DS911DB, $DS911DB);
$query_rsCourses = "SELECT * FROM tblCourse GROUP BY CourseName ORDER BY CourseID";
$rsCourses = mysql_query($query_rsCourses, $DS911DB) or die(mysql_error());
$row_rsCourses = mysql_fetch_assoc($rsCourses);
$totalRows_rsCourses = mysql_num_rows($rsCourses);

mysql_select_db($database_DS911DB, $DS911DB);
$query_rsResources = "SELECT * FROM tblResources";
$rsResources = mysql_query($query_rsResources, $DS911DB) or die(mysql_error());
$row_rsResources = mysql_fetch_assoc($rsResources);
$totalRows_rsResources = mysql_num_rows($rsResources);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "www.w3.org/TR/html4/strict.dtd">
<html><!-- InstanceBegin template="/Templates/admin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Edit Class</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="911admin.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #000000;
}
body {
margin-left: 10px;
margin-top: 5px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
#Logo {
position:absolute;
width:90px;
height:90px;
z-index:1;
}
#AdminNavigation {
position:absolute;
width:175px;
height:115px;
z-index:2;
top: 105px;
left: 10px;
}
.boxheaders {
color: #FFFFFF;
font-size: 11px;
}
#Header {
position:absolute;
width:610px;
height:90px;
z-index:3;
top: 5px;
left: 110px;
}
#LeftText {
position:absolute;
width:129px;
height:30px;
z-index:1;
left: 5px;
top: 10px;
}
.WelcomeText {
color: #212958;
font-weight: bold;
}
#RightText {
position:absolute;
width:168px;
height:30px;
z-index:2;
left: 441px;
top: 10px;
}
#AdminBody {
position:absolute;
width:515px;
height:500px;
z-index:4;
left: 205px;
top: 105px;
}
-->
</style>
<link href="911admin.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="Logo"><img src="../images/911Logo.jpg" width="90" height="90"></div>
<div id="AdminNavigation">
<table width="175" border="1px" cellpadding="0" cellspacing="0" bordercolor="#202856">
<tr>
<td><table width="175" border="0" cellspacing="0" cellpadding="5">
<tr>
<th bgcolor="#202856" scope="col"><div align="left" class="boxheaders">Schedule Admin </div></th>
</tr>
<tr>
<td>>> <a href="insert_class.php">Insert New Class</a><br>
>> <a href="manage_classes.php">Edit/Delete Class</a> </td>
</tr>
</table></td>
</tr>
</table>
</div>
<div id="Header">
<div id="LeftText"><span class="WelcomeText">Welcome Back <br>
</span>Log Out | <a href="admin_index.php">Admin Home</a> </div>
<div id="RightText">
<SCRIPT LANGUAGE="JavaScript">
var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : ""+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;
document.write(today);
</script>
</div>
</div>
<!-- InstanceBeginEditable name="AdminBody" -->
<div id="AdminBody"><form name="Schedule" method="POST" action="<?php echo $editFormAction; ?>">
<table width="470" border="0" cellspacing="5" cellpadding="0">
<tr>
<td colspan="2" class="BodyText"><span class="SectionHeading">Edit Class </span>
<input name="PrimaryID" type="hidden" id="PrimaryID" value="<?php echo $row_rsSchedule['SchedulePrimaryID']; ?>">
<br>
</td>
</tr>
<tr>
<td width="174" class="BodyText">Class # </td>
<td width="281"><input name="ScheduleID" type="text" class="textboxrequired" id="ScheduleID" value="<?php echo $row_rsSchedule['ScheduleID']; ?>" size="10" maxlength="10"></td>
</tr>
<tr>
<td class="BodyText">Course</td>
<td><select name="ScheduleCourseID" class="textboxrequired" id="ScheduleCourseID">
<?php
do {
?><option value="<?php echo $row_rsCourses['CourseID']?>"<?php if (!(strcmp($row_rsCourses['CourseID'], $row_rsSchedule['ScheduleCourseID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsCourses['CourseName']?></option>
<?php
} while ($row_rsCourses = mysql_fetch_assoc($rsCourses));
$rows = mysql_num_rows($rsCourses);
if($rows > 0) {
mysql_data_seek($rsCourses, 0);
$row_rsCourses = mysql_fetch_assoc($rsCourses);
}
?>
</select></td>
</tr>
<tr>
<td class="BodyText">Course Type <em>(weekday, weekends, etc.) </em></td>
<td><input name="ScheduleCourseType" type="text" class="textboxrequired" id="ScheduleCourseType" value="<?php echo $row_rsSchedule['ScheduleCourseType']; ?>" size="20" maxlength="50"></td>
</tr>
<tr>
<td class="BodyText">Parent School </td>
<td><select name="ScheduleLocationID" class="textboxrequired" id="ScheduleLocationID" onChange="MM_validateForm('ScheduleID','','R','ScheduleCourseType','','R','ScheduleStartDate','','R','ScheduleEndDate','','R','ScheduleStartTime','','R','ScheduleEndTime','','R','ScheduleOnlineSeats','','R');return document.MM_returnValue">
<?php
do {
?><option value="<?php echo $row_rsLocations['LocationID']?>"<?php if (!(strcmp($row_rsLocations['LocationID'], $row_rsSchedule['ScheduleLocationID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsLocations['LocationName']?></option>
<?php
} while ($row_rsLocations = mysql_fetch_assoc($rsLocations));
$rows = mysql_num_rows($rsLocations);
if($rows > 0) {
mysql_data_seek($rsLocations, 0);
$row_rsLocations = mysql_fetch_assoc($rsLocations);
}
?>
</select></td>
</tr>
<tr>
<td class="BodyText">Class Location </td>
<td><select name="ScheduleResourceID" class="textboxrequired" id="ScheduleResourceID">
<?php
do {
?><option value="<?php echo $row_rsResources['ResourceID']?>"<?php if (!(strcmp($row_rsResources['ResourceID'], $row_rsSchedule['ScheduleResourceID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsResources['ResourceName']?></option>
<?php
} while ($row_rsResources = mysql_fetch_assoc($rsResources));
$rows = mysql_num_rows($rsResources);
if($rows > 0) {
mysql_data_seek($rsResources, 0);
$row_rsResources = mysql_fetch_assoc($rsResources);
}
?>
</select></td>
</tr>
<tr>
<td class="BodyText">Dates <em>(yyyy-mm-dd)</em> </td>
<td><input name="ScheduleStartDate" type="text" class="textboxrequired" id="ScheduleStartDate" value="<?php echo $row_rsSchedule['ScheduleStartDate']; ?>" size="10" maxlength="10">
-
<input name="ScheduleEndDate" type="text" class="textboxrequired" id="ScheduleEndDate" value="<?php echo $row_rsSchedule['ScheduleEndDate']; ?>" size="10" maxlength="10"></td>
</tr>
<tr>
<td class="BodyText">Days</td>
<td valign="middle" class="BodyText"><input <?php if (!(strcmp($row_rsSchedule['ScheduleMonday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleMonday" type="checkbox" id="ScheduleMonday" value="1">
M
<input <?php if (!(strcmp($row_rsSchedule['ScheduleTuesday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleTuesday" type="checkbox" id="ScheduleTuesday" value="1">
T
<input <?php if (!(strcmp($row_rsSchedule['ScheduleWednesday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleWednesday" type="checkbox" id="ScheduleWednesday" value="1">
W
<input <?php if (!(strcmp($row_rsSchedule['ScheduleThursday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleThursday" type="checkbox" id="ScheduleThursday" value="1">
TH
<input <?php if (!(strcmp($row_rsSchedule['ScheduleFriday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleFriday" type="checkbox" id="ScheduleFriday" value="1">
F
<input <?php if (!(strcmp($row_rsSchedule['ScheduleSaturday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleSaturday" type="checkbox" id="ScheduleSaturday" value="1">
SA
<input <?php if (!(strcmp($row_rsSchedule['ScheduleSunday'],1))) {echo "checked=\"checked\"";} ?> name="ScheduleSunday" type="checkbox" id="ScheduleSunday" value="1">
SU</td>
</tr>
<tr>
<td class="BodyText">Time <em>(24-hour format hh:mm) </em></td>
<td><input name="ScheduleStartTime" type="text" class="textboxrequired" id="ScheduleStartTime" value="<?php echo $row_rsSchedule['ScheduleStartTime']; ?>" size="10" maxlength="5">
-
<input name="ScheduleEndTime" type="text" class="textboxrequired" id="ScheduleEndTime" value="<?php echo $row_rsSchedule['ScheduleEndTime']; ?>" size="10" maxlength="5"></td>
</tr>
<tr>
<td class="BodyText">Online Seats </td>
<td><input name="ScheduleOnlineSeats" type="text" class="textboxrequired" id="ScheduleOnlineSeats" value="<?php echo $row_rsSchedule['ScheduleOnlineSeats']; ?>" size="3" maxlength="3"></td>
</tr>
<tr>
<td colspan="2"><input name="Insert" type="submit" class="button" id="Insert" value="Update">
 
<input name="Clear" type="reset" class="button" id="Clear" value="Clear"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>

<input type="hidden" name="MM_update" value="Schedule">
</form></div><!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsSchedule);

mysql_free_result($rsLocations);

mysql_free_result($rsCourses);

mysql_free_result($rsResources);
?>

Replies

Replied 12 Feb 2007 11:02:20
12 Feb 2007 11:02:20 Roddy Dairion replied:
Check the path to the manage_classes.php page.

Reply to this topic