I'm trying to enable a simple updating capability to a website. On one of the pages I have a list of current shows for a band. If one of the band members is logged in they can update show information. Here is the code for that page:
<?php
$query = "SELECT * " .
"FROM shows" ;
$result = mysql_query($query, $link)
or die(mysql_error());
$num_shows = mysql_num_rows($result);
$show_details = '';
while ($row = mysql_fetch_array($result)) {
$show_id = $row['show_id'];
$show_date = $row['show_date'];
$show_venue = $row['show_venue'];
$venue_url = $row['venue_url'];
$venue_address = $row['venue_address'];
$venue_phone = $row['venue_phone'];
$venue_maplink = $row['venue_maplink'];
$show_details .=<<<EOD
<h3>$show_date</h3>
<p><a href="$venue_url">$show_venue</a><br />
$venue_address <a href="$venue_maplink">Map it</a><br />
$venue_phone</p>
<a href="editshow.php?cmd=edit&show_id=$show_id">Edit show</a><hr />
EOD;
}
echo $show_details;
?>
Then, the link takes them to a page with the populated form fields where they can make the changes and submit. The code for that page:
<?php
if($GET["cmd"]=="edit" || $POST["cmd"]=="edit")
{
if (!isset($POST["submit"]))
{
$show_id = $GET["show_id"];
$sql = "SELECT * FROM shows WHERE show_id=$show_id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="post">
<input type=hidden name="show_id" value="<?php echo $myrow["show_id"] ?>">
Show Date:<INPUT TYPE="text" NAME="show_date" VALUE="<?php echo $myrow["show_date"] ?>"><br />
Show Venue<INPUT TYPE="text" NAME="show_venue" VALUE="<?php echo $myrow["show_venue"] ?>"><br />
Venue Url:<INPUT TYPE="text" NAME="venue_url" VALUE="<?php echo $myrow["venue_url"] ?>"><br />
Venue Address:<INPUT TYPE="text" NAME="venue_address" VALUE="<?php echo $myrow["venue_address"] ?>"><br />
Venue Phone:<INPUT TYPE="text" NAME="venue_phone" VALUE="<?php echo $myrow["venue_phone"] ?>"><br />
Venue Maplink:<INPUT TYPE="text" NAME="venue_maplink" VALUE="<?php echo $myrow["venue_maplink"] ?>"><br />
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if (isset($POST["submit"]))
{
$show_id = "show_id";
$show_date = $POST["show_date"];
$show_venue = $POST["show_venue"];
$venue_url = $POST["venue_url"];
$venue_address = $POST["venue_address"];
$venue_phone = $POST["venue_phone"];
$venue_maplink = $_POST["venue_maplink"];
$sql = "UPDATE shows SET show_date='$show_date',show_venue='$show_venue',venue_url='$venue_url', venue_address='$venue_address',venue_phone='$venue_phone',venue_maplink='$venue_maplink' WHERE show_id=$show_id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>[/COLOR]
But on submittion of the data, I get an error:
Notice: Undefined index: cmd in C:\Apache2.2\htdocs\Devils\editshow.php on line 30
and the information isn't updated.
I'm kind of new so it may be something obvious. Also, if there's a better way to do this I'm open to ideas. Thanks.