PDA

View Full Version : Troubleshooting - Why isn't this working?



Medyman
10-07-2007, 12:09 AM
<?
include_once('../php/config.php');
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
$id=$HTTP_GET_VARS['id'];

if($id)
{
$sql="SELECT * FROM fiction WHERE id='$id'";
$result=mysql_query($sql);
$rs=mysql_fetch_array($result);
}
if($_POST['edit_fiction'] == "Update")
{
$id=$_POST['id'];
$type=$_POST['type'];
$title=$_POST['title'];
$author=$_POST['author'];
$desc=$_POST['desc'];
$content=$_POST['content'];
/*$cust_address1=$_POST['image'];*/
$image=$_FILES['image']['name'];



if($_FILES['image']['name'])
{
//upload file
$target_path = "upload/";

$target_path = $target_path . basename( $_FILES['image']['name']);

move_uploaded_file($_FILES['image']['tmp_name'], $target_path);

//end upload file

$thumb=$_FILES['thumb']['name'];

//upload file2
$target_path = "../upload/";

$target_path = $target_path . basename( $_FILES['thumb']['name']);

if(move_uploaded_file($_FILES['thumb']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['thumb']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
//end upload file2


$sql = "UPDATE fiction SET title='$title', author='$author', desc='$desc', content='$content', thumb='$thumb', image ='$image', featured='$type' where id = '$id'";
} else {
$sql = "UPDATE fiction SET title='$title', author='$author', desc='$desc', content='$content' where id = '$id'";
}

$result=mysql_query($sql);


//$_SESSION['sess_msg'] = "User Information Updated Successfully.";
//header("Location: preview_fiction.php");
?>
<script type="text/javascript">

window.location='fiction.php';

</script>
<?
exit;
}
include("header.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head></head><body>

<div class='border'>
<form action="" method="post" enctype="multipart/form-data">
<h4>Fiction</h4>
<select name="type" id="type">
<option value="1" <?php if($rs['featured']=='1'){ echo 'selected="selected"';}?>>Normal Entry</option>
<option value="2" <?php if($rs['featured']=='2'){ echo 'selected="selected"';}?>>Featured Entry</option>
<option value="3" <?php if($rs['featured']=='3'){ echo 'selected="selected"';}?>>Archived Entry</option>
</select> <span class="h7">CATEGORY // POSITION ON FICTION PAGE</span><br />
<input type='file' name="thumb" id="thumb"> <span class="h7">100 x 100 // THUMBNAIL FOR NORMAL ENTRY</span><br />
<input type='file' name="image" id="image"> <span class="h7">444 x 166 // BANNER FOR FEATURED ENTRY</span><br />
<input type='text' name="title" id="title" value='<?=$rs['title'];?>'> <span class="h7">TITLE // ASCII (VARCHAR 255)</span><br />
<input type='text' name="author" id="author" value='<?=$rs['author'];?>'> <span class="h7">AUTHOR // ASCII (VARCHAR 255)</span><br />
<textarea name="desc" id="desc"><?=$rs['desc'];?></textarea>
<textarea name='content' id='content' class='txtEditor'><?=$rs['content'];?></textarea><input name="id" type="hidden" value="<?=$rs['id'];?>" /><input type="submit" name="edit_fiction" value="Update" class="submit" /></form>


</body>
</html>


When I hit update, it's not remitting the changes to the MySQL database.

Medyman
10-07-2007, 08:35 PM
Solved.

desc is a SQL reserved keyword

djr33
10-07-2007, 09:17 PM
Ah, good catch. I didn't see anything wrong either.