Hey everyone. I had a post over in the dreamweaver forum, but they suggested i put one here, so here it is 🙂 My problem is that can not get my update page to update records in MySQL. The post i made earlier is here . That explains my problem in more detail. The code i have in my pages is as follows:
This is the page that displays the possible records to edit:
<?php require_once('../Connections/conn_virtualhangar.php'); ?>
<?php
mysql_select_db($database_conn_virtualhangar, $conn_virtualhangar);
$query_rsNews = "SELECT * FROM tblnews ORDER BY ArticleDate DESC";
$rsNews = mysql_query($query_rsNews, $conn_virtualhangar) or die(mysql_error());
$row_rsNews = mysql_fetch_assoc($rsNews);
$totalRows_rsNews = mysql_num_rows($rsNews);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>Available News Items</p>
<table width="84%" border="1">
<tr align="center" valign="middle">
<td width="22%">Date</td>
<td width="56%">Article Title </td>
<td width="11%">EDIT</td>
<td width="11%">DELETE</td>
</tr>
<?php do { ?>
<tr align="center" valign="middle">
<td><?php echo $row_rsNews['ArticleDate']; ?></td>
<td><?php echo $row_rsNews['ArticleTitle']; ?></td>
<td><a href="edit.php?ID=<?php echo $row_rsNews['ArticleID']; ?>">EDIT</a></td>
<td><a href="delete.php?ID=<?php echo $row_rsNews['ArticleID']; ?>">DELETE</a></td>
</tr>
<?php } while ($row_rsNews = mysql_fetch_assoc($rsNews)); ?>
</table>
<p><a href="index.html">Return To Admin Index </a></p>
</body>
</html>
<?php
mysql_free_result($rsNews);
?>
And here is the page that allows me to actually edit it:
<?php require_once('../Connections/conn_virtualhangar.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"] == "frmUpdate")) {
$updateSQL = sprintf("UPDATE tblnews SET ArticleTitle=%s, ArticleContent=%s, ArticleAuthor=%s, AuthorEmail=%s, ArticleDate=%s WHERE ArticleID=%s",
GetSQLValueString($_POST['ArticleTitle'], "text"),
GetSQLValueString($_POST['ArticleContent'], "text"),
GetSQLValueString($_POST['ArticleAuthor'], "text"),
GetSQLValueString($_POST['AuthorEmail'], "text"),
GetSQLValueString($_POST['ArticleDate'], "date"),
GetSQLValueString($_POST['ArticleID'], "int"));
mysql_select_db($database_conn_virtualhangar, $conn_virtualhangar);
$Result1 = mysql_query($updateSQL, $conn_virtualhangar) or die(mysql_error());
$updateGoTo = "edit-news.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_rsUpdate = "1";
if (isset($_GET['ID'])) {
$colname_rsUpdate = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_conn_virtualhangar, $conn_virtualhangar);
$query_rsUpdate = sprintf("SELECT * FROM tblnews WHERE ArticleID = %s", $colname_rsUpdate);
$rsUpdate = mysql_query($query_rsUpdate, $conn_virtualhangar) or die(mysql_error());
$row_rsUpdate = mysql_fetch_assoc($rsUpdate);
$totalRows_rsUpdate = mysql_num_rows($rsUpdate);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>Edit News Item Below</p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="frmUpdate" id="frmUpdate">
<table width="100%" border="1">
<tr>
<td width="14%">Article Title </td>
<td width="86%"><input name="ArticleTitle" type="text" id="ArticleTitle" value="<?php echo $row_rsUpdate['ArticleTitle']; ?>"></td>
</tr>
<tr>
<td>Article Author </td>
<td><input name="ArticleAuthor" type="text" id="ArticleAuthor" value="<?php echo $row_rsUpdate['ArticleAuthor']; ?>"></td>
</tr>
<tr>
<td>Author Email </td>
<td><input name="AuthorEmail" type="text" id="AuthorEmail" value="<?php echo $row_rsUpdate['AuthorEmail']; ?>"></td>
</tr>
<tr>
<td>Article Date </td>
<td><input name="ArticleDate" type="text" id="ArticleDate" value="<?php echo $row_rsUpdate['ArticleDate']; ?>"></td>
</tr>
<tr>
<td>Article Content </td>
<td><textarea name="ArticleContent" cols="45" rows="10" id="ArticleContent"><?php echo $row_rsUpdate['ArticleContent']; ?></textarea></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update Record"></td>
<td><input name="ArticleID" type="hidden" id="ArticleID"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="frmUpdate">
</form>
<p><a href="index.html">Return To Administration Menu </a></p>
</body>
</html>
<?php
mysql_free_result($rsUpdate);
?>
I am not much of a coder, although i do understand the basics (i worked with VB for a little while), and i just made those with dreamweaver. Thanks in advance for any help...i really appreciate it! 🙂