This is for a Collectible Card Catalog.
Add_card.php:
if(isset($_POST['submit'])){// handle the form
// Connect to the database.
require_once ('incl/mysql_connect.php');
// Query the database.
// The insert condition.
$query = "INSERT INTO card (card_id, name, color_id, ccost, setone, settwo, setthree, setfour, setfive, setsix, setseven, seteight, setnine, setten, seteleven, settwelve, setthirteen, setfourteen, setfifteen, type_id, typeext_id, quantity, cost) VALUES ('$card_id', '$name', '$color_id', '$ccost', '$setone', '$settwo', '$setthree', '$setfour', '$setfive', '$setsix', '$setseven', '$seteight', '$setnine', '$setten', '$seteleven', '$settwelve', '$setthirteen', '$setfourteen', '$setfifteen', '$type_id', '$typeext_id', '$quantity', '$cost')";
echo mysql_error();
<table width="100%" border="0" cellspacing="1" cellpadding="1" class=outline>
<tr><td align=center colspan=2>Add Card</td></tr>
<tr><td valign="top" colspan=2> </td></tr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr><td valign="top" colspan=2>Name: <input type="text" name="name" size="75" maxlength="75" value="<?php if (isset($POST['name'])) echo $POST['name']; ?>" /></td>
<td valign="top">Quantity: <input type="text" name="quantity" size="5" maxlength="5" value="<?php if (isset($POST['quantity'])) echo $POST['quantity']; ?>" /></td>
</tr>
<tr><td valign="top" width=33%>Color:
<select name="color_id">
<option value="">Select Color</option>
<?php
$q = "select color_id, color from color order by color";
$result = mysql_query($q) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
if ($id == $color_id)
echo "<option value=\"$color_id\" selected>$color</option>";
else
echo "<option value=\"$color_id\">$color</option>";
}
?>
</select>
</td>
<td valign="top" width=33%>Type:
<select name="type_id">
<option value="">Select Type</option>
<?php
$q = "select type_id, type from type order by type";
$result = mysql_query($q) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
if ($id == $type_id)
echo "<option value=\"$type_id\" selected>$type</option>";
else
echo "<option value=\"$type_id\">$type</option>";
}
?>
</select>
</td>
<td valign="top" width=33%>Extended:
<SELECT NAME="typeext_id" class=title>
<option value="">Select Extended Type</option>
<?php
$q = "select typeext_id, typeext from type_extended order by typeext";
$result = mysql_query($q) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
if ($id == $typeext_id)
echo "<option value=\"$typeext_id\" selected>$typeext</option>";
else
echo "<option value=\"$typeext_id\">$typeext</option>";
}
?>
</SELECT></td></tr>
<tr><td valign="top" colspan=3>Casting Cost: <input type="text" name="ccost" size="100" maxlength="100" value="<?php if (isset($POST['ccost'])) echo $POST['ccost']; ?>" /></td>
</tr>
<tr><td valign="top">Set 1:
<select name="setone">
<option value=""></option>
<?php
$q = "select cardset_id, cardset from cardset order by cardset";
$result = mysql_query($q) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
if ($id == $cardset_id)
echo "<option value=\"$cardset\" selected>$cardset</option>";
else
echo "<option value=\"$cardset\">$cardset</option>";
}
?>
</select>
</td>
<td valign="top">Set 2: <SELECT NAME="settwo" class=title>
<option value=""></option>
<?php
$q = "select cardset_id, cardset from cardset order by cardset";
$result = mysql_query($q) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
if ($id == $cardset_id)
echo "<option value=\"$cardset\" selected>$cardset</option>";
else
echo "<option value=\"$cardset\">$cardset</option>";
}
?>
</SELECT></td>
<td valign="top">Set 3: <SELECT NAME="setthree" class=title>
<option value=""></option>
<?php
$q = "select cardset_id, cardset from cardset order by cardset";
$result = mysql_query($q) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
if ($id == $cardset_id)
echo "<option value=\"$cardset\" selected>$cardset</option>";
else
echo "<option value=\"$cardset\">$cardset</option>";
}
?>
</SELECT></td></tr>
// Repeated up to Set 15.
<tr><td valign="top" colspan=2>$$ Cost: <input type="text" name="cost" size="50" maxlength="50" value="<?php if (isset($POST['cost'])) echo $POST['cost']; ?>" /></td></tr>
<tr><td valign="top" colspan=2><center><input class="title" type="submit" name="submit" value="Add A Card" /></center>
</td></tr>
</form>
</table>
Card_list.php (which has the link for the update page)
require_once ('incl/mysql_connect.php'); // Connect to the database.
$row['card_id']= $_GET['card_id'];
echo"<table width=100% border=0 class=outline>
<tr>
<td align=justify width=25% valign=top><b>Card</b> (Quantity)</td>
<td align=justify width=25% valign=top><b>Color</b></td>
<td align=justify width=25% valign=top><b>Type</b></td>
</tr>";
$result = mysql_query("SELECT card.*, type.*, type_extended.*, color.* FROM card , type , color , type_extended WHERE 1 AND card.color_id = color.color_id AND card.type_id=type.type_id AND card.typeext_id= type_extended.typeext_id ORDER BY name ASC");
echo mysql_error();
if (mysql_num_rows($result))
while($row = mysql_fetch_array($result)) {
echo "<tr><td align=justify width=25% valign=top><b>" . $row['name'] . "</b> (" . $row['quantity'] . ")</td>
<td align=justify width=25% valign=top>" . $row['color'] . " </td><td align=justify width=25% valign=top>" . $row['type'] . " " . $row['typeext'] . "</td><td align=right width=25% valign=top><a href='update.php?id=".$row['card_id']."'>Update</a></td>
</tr>";
}
echo"</table><p></p>";
Now onto the update.php page which is where I am having a bit of a problem. I have got it to the point where the info will actually post into the form for editing but I have a few questions on select. I know how to populate it on the Add a card section but I am not sure how to implement the <Select>s in this current form.
require_once ('incl/mysql_connect.php');
// Connect to the MySQL Database
// This MySQL Query basically says grab the row that matches the id number.
$row['card_id']= $_GET['card_id'];
$result = mysql_query("SELECT card.* FROM card WHERE 1 AND card_id = '$id'");
echo mysql_error();
if (mysql_num_rows($result))
while($row = mysql_fetch_array($result)) {
echo "<table width=100% border=0 cellspacing=1 cellpadding=1 class=outline>
<tr><td align=center colspan=3>Edit " . $row['name'] . "</td></tr>
<tr><td valign=top colspan=3> </td></tr>";
echo "<form action=\"update_record.php?id={$row['card_id']}\" method=\"post\">";
echo "<tr>
<td valign=top colspan=2>Name: <input type=text name=name size=75 maxlength=75 value=" . $row['name'] . "></td>
<td valign=top>Quantity: <input type=text name=name size=5 maxlength=5 value=" . $row['quantity'] . "></td>
</tr>";
echo "<tr><td valign=top colspan=3>$$ Cost: <input type=text name=cost size=10 maxlength=10 value=" . $row['cost'] . "></td></tr>";
;
// This is where my problem arises. There are a total of 15 sets a card can come from with cards often being in more than one set.
echo "<tr><td valign=top width=33%>Card Set 1:
<select name=cardset_id>
<option value=" . $row['cardset_id'] . ">" . $row['setone'] . "</option>
<option></option>
</select>
</td>
<td valign=top width=33%>Card Set 2:
<select name=cardset_id>
<option value=" . $row['cardset_id'] . ">" . $row['settwo'] . "</option>
<option></option>
</select>
</td>
<td valign=top width=33%>Card Set 3:
<select name=cardset_id>
<option value=" . $row['cardset_id'] . ">" . $row['setthree'] . "</option>
<option></option>
</select>
</td></tr>
";
echo "</form>";
echo "</table>";
}