2004-09-20, 04:05 AM
(matt, please dont answer unless you have something kind to say please)
(oh and remember, I changed it from "I know php but not well" to "Im learning php" )
I call upon all smart web program people, I have a query, a mySQL query (haha )
Ok, here's the deal. I have a page that works fine, so I copied those files and edited it to be able to suit another part of my site. Nothing except the extra feilds were added. But heres the problem, it doesn't work. Nothing has chaged except the name and number of feilds. I dont know whats wrong. Perhaps an error of some kind??
See if you can find something wrong with these:
index.php:
edit.php:
config.php:
Oh, and if you feel extra kind, anyone know of a way (dont have to code it if you dont want, just link me somewhere or give me quidelines) to remember what I have put and show in checkbox?? value="<? echo $download['catid']; ?>" and other select boxes in the first code wont accept those
(oh and remember, I changed it from "I know php but not well" to "Im learning php" )
I call upon all smart web program people, I have a query, a mySQL query (haha )
Ok, here's the deal. I have a page that works fine, so I copied those files and edited it to be able to suit another part of my site. Nothing except the extra feilds were added. But heres the problem, it doesn't work. Nothing has chaged except the name and number of feilds. I dont know whats wrong. Perhaps an error of some kind??
See if you can find something wrong with these:
index.php:
<?php
require_once ("../../../../config.php");
if (is_numeric($id)) {
$query = mysql_query("SELECT * FROM `download_items` WHERE id='$id'") or die(mysql_error());
}
else {
$query = mysql_query("SELECT * FROM `download_items`") or die(mysql_error());
}
$download = mysql_fetch_array($query);
require ("edit.php");
?>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="<? echo $PHP_SELF; ?>"
enctype="multipart/form-data">
<input name="id" type="hidden" value="<? echo $download['id']; ?>">
<table border="0" summary="" align="center" cellpadding="5"
class="black">
<tr>
<td align="center"><font color="white">Field</font</td>
<td align="center"><font color="white">Value</font></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC">catid<br>
<?php if (array_key_exists("No catid",$errors)) print_error($errors["No catid"]); ?>
</td>
<td bgcolor="#CCCCCC"><select name="catid">
<option value="" <?php if ($_REQUEST['catid'] == "") echo "selected"; ?>></option>
<?php
$sql = "select * from `download_itemscat`";
$query = mysql_query($sql, $connection);
$counter = 0;
while ($catinfo= mysql_fetch_assoc($query)) {
$counter++;
if ($counter == 1) {
echo "<option value=\"" . $catinfo["catid"] . "\"";
if ($_REQUEST["catid"] == $catinfo['catid']) echo "selected";
echo ">". $catinfo["catname"] . "</option>
";
$counter = 0;
}
}
?>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#DDDDDD">mplink<br>
<?php if (array_key_exists("No mplink",$errors)) print_error($errors["No mplink"]); ?>
</td>
<td bgcolor="#DDDDDD"><input name="mplink" type="text" size="40"
value="<? echo $download['mplink']; ?>" maxlength="225"></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC">name<br>
<?php if (array_key_exists("No name",$errors)) print_error($errors["No name"]); ?>
</td>
<td bgcolor="#CCCCCC"><input name="name" type="text" size="40"
value="<? echo $download['name']; ?>" maxlength="255"></td>
</tr>
<tr>
<td align="center" bgcolor="#DDDDDD">dllink<br><?php if (array_key_exists("No dllink",$errors)) print_error($errors["No dllink"]); ?>
</td>
<td bgcolor="#DDDDDD"><input name="dllink" type="text" size="40"
value="<? echo $download['dllink']; ?>" maxlength="255"></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC">desc<br><?php if (array_key_exists("No desc",$errors)) print_error($errors["No desc"]); ?>
</td>
<td bgcolor="#CCCCCC">
<textarea name="desc" rows="7" cols="40"><?php echo $download['desc']; ?></textarea></td>
</tr>
<tr>
<td align="center" bgcolor="#DDDDDD">rate</td>
<td bgcolor="#DDDDDD"><select name="rate">
<option value="0" <?php if ($_REQUEST['rate'] == "0") echo "selected"; ?>>0 - Not Yet Rated</option>
<option value="1" <?php if ($_REQUEST['rate'] == "1") echo "selected"; ?>>1 - Poor</option>
<option value="2" <?php if ($_REQUEST['rate'] == "2") echo "selected"; ?>>2</option>
<option value="3" <?php if ($_REQUEST['rate'] == "3") echo "selected"; ?>>3 - Ok</option>
<option value="4" <?php if ($_REQUEST['rate'] == "4") echo "selected"; ?>>4</option>
<option value="5" <?php if ($_REQUEST['rate'] == "5") echo "selected"; ?>>5 - Excellent</option>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC">type</td>
<td bgcolor="#CCCCCC"><select name="type">
<option value="NotAvailable" <?php if ($_REQUEST['type'] == "NotAvailable") echo "selected"; ?>>Not Yet Available</option>
<option value=""></option>
<option value="Freeware" <?php if ($_REQUEST['type'] == "Freeware") echo "selected"; ?>>Freeware</option>
<option value="Freeware - ExtendableF" <?php if ($_REQUEST['type'] == "Freeware - ExtendableF") echo "selected"; ?>>Freeware - Extendable F</option>
<option value="Freeware - ExtendableS" <?php if ($_REQUEST['type'] == "Freeware - ExtendableS") echo "selected"; ?>>Freeware - Extendable S</option>
<option value="Freeware - ExtendableR" <?php if ($_REQUEST['type'] == "Freeware - ExtendableR") echo "selected"; ?>>Freeware - Extendable R</option>
<option value="Freeware - ExtendableC" <?php if ($_REQUEST['type'] == "Freeware - ExtendableC") echo "selected"; ?>>Freeware - Extendable C</option>
<option value="Freeware - ExtendableFS" <?php if ($_REQUEST['type'] == "Freeware - ExtendableFS") echo "selected"; ?>>Freeware - Extendable F-S</option>
<option value=""></option>
<option value="Shareware" <?php if ($_REQUEST['type'] == "Shareware") echo "selected"; ?>>Shareware</option>
<option value="Shareware - ExtendableF" <?php if ($_REQUEST['type'] == "Shareware - ExtendableF") echo "selected"; ?>>Shareware - Extendable F</option>
<option value="Shareware - ExtendableS" <?php if ($_REQUEST['type'] == "Shareware - ExtendableS") echo "selected"; ?>>Shareware - Extendable S</option>
<option value="Shareware - ExtendableR" <?php if ($_REQUEST['type'] == "Shareware - ExtendableR") echo "selected"; ?>>Shareware - Extendable R</option>
<option value="Shareware - ExtendableC" <?php if ($_REQUEST['type'] == "Shareware - ExtendableC") echo "selected"; ?>>Shareware - Extendable C</option>
<option value="Shareware - ExtendableFS" <?php if ($_REQUEST['type'] == "Shareware - ExtendableFS") echo "selected"; ?>>Shareware - Extendable F-S</option>
</select></td>
</tr>
<tr>
<td align="center" bgcolor="#DDDDDD">pic<br>
<?php if (array_key_exists("No pic",$errors)) print_error($errors["No pic"]); ?>
</td>
<td bgcolor="#DDDDDD"><input name="pic" type="text" size="40"
maxlength="225" value="<? echo $download['pic']; ?>"></td>
</tr>
<tr>
<td colspan="2">
<div align="center"><input type="submit" value=
"Edit Download"></div>
</td>
</tr>
</table>
</form>
</body>
</html>
edit.php:
<?php
require_once ("../../../../config.php");
$errors = array();
if ($_SERVER['REQUEST_METHOD']=="POST"){
$errors = process_form($errors);
}
function process_form($errors) {
if (!get_magic_quotes_gpc()) {
function addslashes_deep($value) {
$value = is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
return $value;
}
$_REQUEST = array_map('addslashes_deep', $_REQUEST);
}
$id = $_REQUEST['id'] ;
$catid = $_REQUEST['catid'] ;
$mplink = $_REQUEST['mplink'] ;
$name = $_REQUEST['name'] ;
$dllink = $_REQUEST['dllink'] ;
$desc = $_REQUEST['desc'] ;
$rate = $_REQUEST['rate'] ;
$type = $_REQUEST['type'] ;
$pic = $_REQUEST['pic'] ;
if (empty($catid)) {
$errors["No catid"]="Empty catid";
}
if (empty($mplink)) {
$errors["No mplink"]="Empty mplink";
}
if (empty($name)) {
$errors["No name"]="Empty name";
}
if (empty($dllink)) {
$errors["No dllink"]="Empty dllink";
}
if (empty($desc)) {
$errors["No desc"]="Empty desc";
}
if (empty($pic)) {
$errors["No pic"]="Empty pic";
}
if (count($errors) == 0) {
echo "UPDATE `download_items` SET catid='$catid', mplink='$mplink', name='$name', dllink='$dllink', desc='$desc', rate='$rate', type='$type', pic='$pic' WHERE id='$id'\n";
if (!mysql_query("UPDATE `download_items` SET catid='$catid', mplink='$mplink', name='$name', dllink='$dllink', desc='$desc', rate='$rate', type='$type', pic='$pic' WHERE id='$id'")) {
echo "<head><link href=../../../../../scripts/styles.css rel=stylesheet type=text/css></head>\n";
echo "<table summary= border=1 class=double><tr><td>\n";
echo "Processing form..........<br>\n";
echo "Download was not successfully edited..........<br>\n";
echo "Please click submit again..........<br>\n";
echo "</tr></td></table><br>";
} else {
echo "<head><meta http-equiv=refresh content=2;url=../../index.php>\n";
echo "<link href=../../../../../scripts/styles.css rel=stylesheet type=text/css></head>\n";
echo "<table summary= border=1 class=double><tr><td>\n";
echo "Processing form..........<br>\n";
echo "Download successfully edited..........<br>\n";
echo "Refreshing in 2 seconds..........<br>\n";
echo "</tr></td></table><br>";
}
}
return $errors;
}
function print_error($error) {
echo "<b><font color=red>Error:</b> $error</font><br /><br />";
}
?>
config.php:
<?php
$username ="****";
$password ="****";
$database="****";
$connection = mysql_connect("localhost","$username","$password");
@mysql_select_db("$database", $connection) or die( "<br><center><h2>Unable to select database, please refresh.</h2>If problem persists, please contact me using the form and report the error you are receiving if any.</center>");
?>
Oh, and if you feel extra kind, anyone know of a way (dont have to code it if you dont want, just link me somewhere or give me quidelines) to remember what I have put and show in checkbox?? value="<? echo $download['catid']; ?>" and other select boxes in the first code wont accept those