Jump to content

[SOLVED] PHP Command Problem / MySQL Tabels Not Updating


kneifelspy

Recommended Posts

Here is the code.  Maybe one of you can explain to me why when I run this script, NONE of the MySQL tables are updated, even though the script runs without any errors.

 

<body>

<?php

if ($_POST['submit']) {

include('dbinfo.inc.php');

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

$filename = $_FILES['photo']['name'];
$filetype = $_FILES['photo']['type'];
$filesize = $_FILES['photo']['size'];
$tmp_filename = $_FILES['photo']['tmp_name'];

$fp = fopen($tmp_filename, 'r');
$filedata = fread($fp, filesize($tmp_filename));
$filedata = mysql_real_escape_string($filedata);
fclose($fp);

$id = mysql_real_escape_string($_POST['id']);
$issue = mysql_real_escape_string(htmlspecialchars($_POST['issue']));
$release = mysql_real_escape_string(htmlspecialchars($_POST['release']));
$feature1 = mysql_real_escape_string(htmlspecialchars($_POST['feature1']));
$feature2 = mysql_real_escape_string(htmlspecialchars($_POST['feature2']));
$feature3 = mysql_real_escape_string(htmlspecialchars($_POST['feature3']));
$time = mysql_real_escape_string(htmlspecialchars($_POST['time']));

$query="UPDATE issues SET filedata='$filedata', filename='$filename', filetype='$filetype', issue='$issue', release='$release', feature1='$feature1', feature2='$feature2', feature3='$feature3', timestamp='$time' WHERE id='$id'";
mysql_query($query);

echo '<b>Record Successfully Updated!</b><br /><br />';

mysql_close();

include('mag.list.php');

} else {

$id=$_GET['id'];

include('dbinfo.inc.php');

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

$query = "SELECT * FROM issues WHERE id='$id'";
$result = mysql_query($query);

$num = mysql_numrows($result);

mysql_close();

?>

<div class="body">
<table id="main_container" width="1000" border="0" cellpadding="0" cellspacing="0">
	<tr>

<? include('nav.php'); ?>

		<td width="800" align="left" valign="top">

<?

$i = 0;
while ($i < $num) {

	$id = mysql_result($result, $i, 'id');
	$issue = stripslashes(mysql_result($result, $i, 'issue'));
	$release = stripslashes(mysql_result($result, $i, 'release'));
	$feature1 = stripslashes(mysql_result($result, $i, 'feature1'));
	$feature2 = stripslashes(mysql_result($result, $i, 'feature2'));
	$feature3 = stripslashes(mysql_result($result, $i, 'feature3'));
	$timestamp = stripslashes(mysql_result($result, $i, 'timestamp'));

	?>

			<form enctype="multipart/form-data" name="myform" action="<?php echo $PHP_SELF; ?>" method="post">
				<table id="body_container" width="100%" cellpadding="0" cellspacing="10">
					<tr>
						<td colspan="2" align="left" valign="bottom" style="border-bottom: 1px solid black; border-color: #000000;">
							<span class="page_head">Print Issue -- Edit</span><br /><br />
						</td>
					</tr>
					<tr>
						<td colspan="2" align="left" valign="bottom" style="border-bottom: 1px solid black; border-color: #BCCAFF;">
							You may edit the selected print issue using the form below.<br /><br />
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_user">Issue Number:</span>
						</td>
						<td align="left" valign="bottom">
							<input type="hidden" id="id" name="id" value="<? echo $id; ?>" />
							<input type="text" id="issue" name="issue" size="50" maxlength="6" value="<? echo $issue; ?>" class="formbox" />
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_user">Release Date:</span>
						</td>
						<td align="left" valign="bottom">
							<input type="text" id="release" name="release" size="50" maxlength="14" value="<? echo $release; ?>" class="formbox" />
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_user">Cover Image:</span><br />
							<span class="input_auto">2mb or less</span>
						</td>
						<td align="left" valign="bottom">
							<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
							<input type="file" id="photo" name="photo" class="formbox" />  
							<a href="mag.img.php?id=<? echo $id; ?>" target="blank_">Preview Currently Uploaded Image</a>
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_user">Cover Feature:</span>
						</td>
						<td align="left" valign="bottom">
							<input type="text" id="feature_1" name="feature1" size="50" maxlength="100" value="<? echo $feature1; ?>" class="formbox" />
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_user">Inside Feature #1:</span>
						</td>
						<td align="left" valign="bottom">
							<input type="text" id="feature_2" name="feature2" size="50" maxlength="100" value="<? echo $feature2; ?>" class="formbox" />
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_user">Inside Feature #2:</span>
						</td>
						<td align="left" valign="bottom">
							<input type="text" id="feature_3" name="feature3" size="50" maxlength="100" value="<? echo $feature3; ?>" class="formbox" />
						</td>
					</tr>
					<tr>
						<td width="120" align="left" valign="bottom">
							<span class="input_auto">Date Created:</span>
						</td>
						<td align="left" valign="bottom">
							<input type="text" id="time" name="time" size="50" maxlength="18" value="<? echo $timestamp; ?>" class="formbox" />
						</td>
					</tr>
					<tr>
						<td colspan="2" align="right" valign="bottom" style="border-top: 1px solid white; border-color: #BCCAFF;">
							<br />
							<input type="button" value="Preview" onclick="openPreview();" class="button_submit" /> 
							<input type="submit" name="submit" value="Submit" onclick="return confirm('Are you sure you want to MODIFY the selected entry?');" class="button_submit" />
						</td>
					</tr>

				</table>
			</form>

	<?

	++$i;
}

?>

		</td>
	</tr>
</table>
</div>
<?

}

?>

</body>

 

Again, I am getting NO errors.

 

 

This error came up:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release='January 2009', feature1='Change the name!', feature2='CHANGE IT!', feat' at line 1

 

relase is a reserved word in mysql. Use backticks (`) to escape your column/table names.

 

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

 

 

Yeah, I was staring at the code and didn't realize that RELEASE was a reserved word either, probably cause I've never used it before, good to know!  ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.