Hi Guys, been working on this for ages, its driving me nuts and wasting my time as I need to move on to other things...
If I echo the query after hitting submit, i get everything through except the id, which of course renders the query useless as it wont update without it. I tried using $_GET['id'] in the query (as it is being passed through a URL and it wont work, however if I echo the $_GET['id'] in the page, the id is displayed. I have tried setting the $_GET['id'] into a hidden form field and set the query to WHERE id = $_POST['id'] and have tried putting the $_GET['id']into a variable (i think thats what its called) as $id and used that, but nothing... as i said i can echo these on the page, but they are not existing in the query.... heres my code (all of it, so i hope i can get this fixed)...
**************************
**********
**********
**********
**********
**********
**********
***
<?php
ob_start();
include('admin_functions.p
hp');
db_connect(); // function which just connects - db connection status is not an issue.
$query_pplay = "SELECT * FROM products WHERE id = '{$_GET['id']}'";
$pplay = mysql_query($query_pplay) or die(mysql_error());
$row_pplay = mysql_fetch_assoc($pplay);
$query_pplay2 = "SELECT * FROM cats WHERE id = '{$row_pplay['cat_id']}'";
$pplay2 = mysql_query($query_pplay2)
or die(mysql_error());
$row_pplay2 = mysql_fetch_assoc($pplay2)
;
$query_pplay3 = "SELECT DISTINCT * FROM cats ORDER BY title";
$pplay3 = mysql_query($query_pplay3)
or die(mysql_error());
$row_pplay3 = mysql_fetch_assoc($pplay3)
;
if (count($_FILES) > 0 and array_key_exists('image', $_FILES)) {
if (is_uploaded_file($_FILES[
'image']['
tmp_name']
)) {
if ($_FILES['image']['name'] != '') {
$pic_name = "1_" . date("d_m_Y_H_i") . "_" . $_FILES['image']['name'];
} else {
exit; //Can't really do anything if we don't have a filename
}
$uploaddir = '../images/parts/';
$thumbnaildir = '../images/parts/thumbs/';
$sourcefile = $uploaddir . $pic_name;
move_uploaded_file($_FILES
['image'][
'tmp_name'
], $sourcefile);
$pdestfile = "{$thumbnaildir}tn_{$pic_n
ame}";
$g_imgcomp = 50;
$psize = 150;
resampimagejpg($psize, $sourcefile, $pdestfile, $g_imgcomp);
}
}
$p_title = addslashes($_POST['title']
);
$p_desc = addslashes($_POST['descrip
tion']);
$p_cat_id = addslashes($_POST['cat_id'
]);
$p_price = addslashes($_POST['price']
);
$s_title = stripslashes($row_pplay['t
itle']);
$s_description = stripslashes($row_pplay['d
escription
']);
$s_cat_id = stripslashes($row_pplay['c
at_id']);
$s_price = stripslashes($row_pplay['p
rice']);
if (isset($_POST['submit'])) {
if ($_FILES['image']['name'] != '') {
$updateSQL = "UPDATE products SET title='{$p_title}', description='{$p_desc}', cat_id='{$p_cat_id}', price='{$p_price}', image='{$pic_name}' WHERE id = '{$row_pplay['id']}'";
} else {
$updateSQL = "UPDATE products SET title='{$p_title}', description='{$p_desc}', cat_id='{$p_cat_id}', price='{$p_price}' WHERE id = '{$row_pplay['id']}'";
}
$Result1 = mysql_query($updateSQL) or die(mysql_error());
echo $updateSQL ;
// header("Location: index.php?goto=thanks");
}
echo '
<div id="content">
<form method="post" name="form1" action="prod_edit.php" enctype="multipart/form-da
ta">
<table width="400" border="0">
<tr>
<td width="100">Title:</td>
<td><input class="formfield" type="text" name="title" value="' . $s_title . '" size="32"></td>
</tr>
<tr>
<td width="100">Description:</
td>
<td><textarea class="formfield" name="description" cols="100" rows="15">' . $s_description . '</textarea></td>
</tr>
<tr>
<td width="100">In Category:</td>
<td><select name="cat_id">
<option value="' . $row_pplay2['id'] . '">' . $row_pplay2['title'] . '</option>';
do {
echo '<option value="' . $row_pplay3['id'] . '">' . $row_pplay3['title'] . '</option>';
} while ($row_pplay3 = mysql_fetch_assoc($pplay3)
);
echo '
</select></td>
</tr>
<tr>
<td width="100">Price:</td>
<td><input class="formfield" type="text" name="price" value="' . $s_price . '" size="32"></td>
</tr>
<tr>
<td width="100">Image:</td>';
if ($row_pplay['image'] == true) {
echo '<td><a href="../images/parts/' . $row_pplay['image'] . '" target="_blank"><img src="../images/parts/thumb
s/tn_' . $row_pplay['image'] . '" border="0"/></a><br />Upload new Image:<br /><input type="file" name="image" class="formfield"></td>';
} else if ($row_pplay['image'] == false) {
echo '<td><input type="file" name="image" class="formfield"></td>';
}
echo '
</tr>
<tr>
<td width="100"><input class="formsubmit" type="submit" name="submit" value="Update Record" /></td>
<td><input type="reset" class="formsubmit" name="reset" value="Clear Form" /></td>
</tr>
</table>
<form type="hidden" name="id" value="'.$_row_pplay['id']
.'">
</form>
</div>';
mysql_close();
?>
**************************
**********
**********
**********
**********
**********
Thanks Guys! :)
Christian