I realized I could trim down on the number of variables by rearranging things a bit to make it a whole lot less byzantine.
I have defined the variables (it's tucked into the "while" statement), and I know they're working to some extent because a View Source of the generated page shows them returning the proper values. I've tried moving the variable declarations around to different places in the code, but the only placement that works for the HTML generation is where they are currently, everywhere else stops the HTML values as well; nothing at all works for the MySQL insertion.
Definitions:
$ei = $row['feid'];
$name = $row['fename'];
Input for form:
<input type="hidden" name="member_ID" size="50" maxlength="100" value="' . $uid . '" />
<input type="hidden" name="egg_ID" size="50" maxlength="100" value="' . $ei . '" />
<input type="hidden" name="egg_name" size="50" maxlength="100" value="' . $name . '" />
<input type="submit" name="submit" value="Have" />
<input type="hidden" name="submitted" value="TRUE" />
</form></td>';
}
echo '<td>';
echo '<img src="../pics/found/egg-found' . $ei . '.png" height="70px" width="50px"></td><td>';
echo $name;
echo '</td></tr>';
Output in HTML page with proper values in both form and image from those same variables:
<input type="hidden" name="member_ID" size="50" maxlength="100" value="2" />
<input type="hidden" name="egg_ID" size="50" maxlength="100" value="241" />
<input type="hidden" name="egg_name" size="50" maxlength="100" value="dragonearth" />
<input type="submit" name="submit" value="Have" />
<input type="hidden" name="submitted" value="TRUE" />
</form></td><td><img src="../pics/found/egg-found241.png" height="70px" width="50px"></td><td>dragonearth</td>
Why would they work in the generation part, but not be carried through to the insertion part when the $uid from the cookie works throughout?
I even tried removing the JOIN from the SELECT query to see what would happen, but it had no visible effect.
Here's the revamped code:
if (isset ($_COOKIE['ID'])) {
$uid = escape_data($_COOKIE['ID']);
} else {
echo 'oopsie, no cookie for you!';
exit();
}
if (isset($_POST['submitted'])) {
//update the database
$query = "INSERT INTO fd_collection (ID, member_ID, egg_ID, egg_name) VALUES ('NULL', '$uid', '$ei', '$name')";
$result = @mysql_query($query) or die(mysql_error());
}
// make the query
$query = "SELECT fd_eggs.ID AS feid, name AS fename, releasedate AS rdate FROM fd_eggs
LEFT JOIN fd_collection
ON fd_eggs.ID = fd_collection.egg_ID
ORDER BY releasedate DESC, fd_eggs.ID DESC";
$result = @mysql_query($query) or die(mysql_error());
echo '<table width="90%" border="0" cellspacing="5" cellpadding="0">';
$bg = '#eeeeee'; //set row background variable
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //set background colours to alternate rows
$ei = $row['feid'];
$name = $row['fename'];
if ($row['egg_ID'] != 0) {
echo '<tr bgcolor="' . $bg . '"><td width="5%" align="left"><img src="pics/yes.gif"></td>';
} else {
echo '<tr bgcolor="' . $bg . '"><td width="5%" align="left"><form action="' . $_SERVER['PHP_SELF'] . '" method="post">
<input type="hidden" name="member_ID" size="50" maxlength="100" value="' . $uid . '" />
<input type="hidden" name="egg_ID" size="50" maxlength="100" value="' . $ei . '" />
<input type="hidden" name="egg_name" size="50" maxlength="100" value="' . $name . '" />
<input type="submit" name="submit" value="Have" />
<input type="hidden" name="submitted" value="TRUE" />
</form></td>';
}