mojavewolfpup
n00b
- Joined
- Jan 21, 2006
- Messages
- 35
I finally have a working database script, I can add some data into it using a web based form instead of manually putting it in via sql scripting commands, but editing it is a different story.
for example, i'll use "95811" as a code, and that gets added, and for another "pin cart #3" that gets added fine, but if I decide to change "pin cart #3" to "pin cart #4" the edit code will accept it, but then switch "pin cart #4" to "95811" so I have that in the database twice
any idea what would be going on? i'm stumped.
I hope the code below helps, it's what I use. I will be adding in other sql fields also, not just the 2 pictured below so I don't know if that would effect anything also.
for example, i'll use "95811" as a code, and that gets added, and for another "pin cart #3" that gets added fine, but if I decide to change "pin cart #3" to "pin cart #4" the edit code will accept it, but then switch "pin cart #4" to "95811" so I have that in the database twice
any idea what would be going on? i'm stumped.
I hope the code below helps, it's what I use. I will be adding in other sql fields also, not just the 2 pictured below so I don't know if that would effect anything also.
<html>
<head>
<title>Edit An Article</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>
<body>
<?php
include 'library/config.php';
include 'library/opendb.php';
if(isset($_GET['id']))
{
$query = "SELECT id, pinpicsnumber, source".
"FROM adventureland ".
"WHERE id = '{$_GET['id']}'";
$result = mysql_query($query) or die('Fatal Database Error: Contact via AIM Immediately! ' . mysql_error());
list($id, $pinpicsnumber, $source) = mysql_fetch_array($result, MYSQL_NUM);
$source = htmlspecialchars($source);
}
else if(isset($_POST['pinpicsnumber']))
{
$id = $_POST['id'];
$pinpicsnumber = $_POST['pinpicsnumber'];
$source = $_POST['source'];
if(!get_magic_quotes_gpc())
{
$pinpicsnumber = addslashes($pinpicsnumber);
$source = addslashes($pinpicsnumber);
}
// update the article in the database
$query = "UPDATE adventureland ".
"SET pinpicsnumber = '$pinpicsnumber', source = '$source' ".
"WHERE id = '$id'";
mysql_query($query) or die('Fatal Database Error: Contact via AIM Immediately! ' . mysql_error());
// then remove the cached file
$cacheDir = dirname(__FILE__) . '/cache/';
$cacheFile = $cacheDir . '_' . $_GET['id'] . '.html';
@unlink($cacheFile);
// and remove the index.html too because the file list
// is changed
@unlink($cacheDir . 'index.html');
echo "<p align='center'>Article updated</p>";
// now we will display $title & content
// so strip out any slashes
$pinpicsnumber = stripslashes($pinpicsnumber);
$source = stripslashes($source);
}
include 'library/closedb.php';
?>
<form method="post" action="cms-edit.php">
<input type="hidden" name="id" value="<?php echo "$id";?>">
<table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
<tr>
<td width="100">Pinpics Number:</td>
<td><input name="pinpicsnumber" type="text" class="box" id="pinpicsnumber" value="<?php echo "$pinpicsnumber";?>"></td>
</tr>
<tr>
<td width="100">Content</td>
<td><input name="source" type="text" class="box" id="source" value="<?php echo "$source";?>"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Article"></td>
</tr>
</table>
<p align="center"><a href="cms-admin.php">Back to admin page</a></p>
</form>
</body>
</html>