MyBB Community Forums

Full Version: Yet again
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(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" Toungue)

I call upon all smart web program people, I have a query, a mySQL query (haha Big Grin )

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 Sad
MySQL is the devil.
Before you can seriously expect me to read all that, would you care to say what is should do and what it is in fact doing to classify it as "not working"?
ok, it is an edit form for a downloads page. I push edit next to the download I want and it carries the info over to the next page. I then edit it a bit and hit submit, it should then process, however it doesn't.

It keeps saying unsucessful. I fixed a problem with the id not being carried through, but now I see nothing wrong. I echo'd the process and it seems all ok. No matter what I try, it keeps failing Sad

Any help is greatly appreciated. Smile
Syntax-wise, the query seems ok, so it's probably a mismatch with the column names/types. Easiest way to find out - echo mysql_error(); - the mysql engine should tell you what its problem was with the code.
Yea, what he said. Toungue
I put in this:
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'") or die(mysql_error())) {

No errors :/ This is going to be tricky. It echo'ed the process correctly as far as I can tell.
Quote:UPDATE download_items SET catid='1', mplink='Testing', name='Testing this', dllink='Testing', desc='Testing', rate='5', type='Freeware', pic='images/downloads/none.jpg' WHERE id='68'

It keep saying unsuccessful and I dont know why Sad
I don't think you can do an "or die()" in an if. The if will always be true and it's code block will end up executing Toungue
hmm, any ideas then??
You told me not to say anything if it isn't going to be nice, so no.
Pages: 1 2