web script doesn't work on update of database
| From: | Chip Wiegand | Date: | Tue, 27 Apr 2004 14:26:30 +0000 |
| Subject: | web script doesn't work on update of database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-184760@lists.php.net to get a copy of this message | ||
I am making a web app for a trade show schedule, so far everything is
working except for one part that allows editing (updating) the existing
info. The script first allows adding a new show to the database - name,
start date, end date, location. That works fine. There is a manage screen
which lists all shows in the database and has a edit and a delete button
for each show. That works fine. The delete button works fine. The edit
button brings up a screen where all fields are displayed in editable
fields and can be changed. This is what is broken. I make any change or no
change and the data in 3 particular fields (e_month, e_day, e_year) is
always reset to zeros. I tested by adding the appropriate info from the
add shows screen and then opened the edit screen, the info is displayed
correctly, but after hitting the submit button those 3 fields are reset to
zero. I also manually added the appropriate numbers in those field in
phpMyAdmin, opened the edit screen and didn't change anything, just hit
the submit button, and those 3 fields are reset to zero. I cannot find
anything wrong with the code. The code of the two screens, show list and
show edit, are listed below.
Thanks,
--
Chip Wiegand
Computer Services
Simrad, Inc
www.simradusa.com
chip.wiegand@simrad.com
------------------------------------------------------------------------------------------------------------
First the code for the show edit screen, this is the body of the html page
only -
------------------------------------------------------------------------------------------------------------
<body class=".c1">
<br />
<br />
<table summary="" class="c6" align="center">
<tr>
<td>
<table summary="" border="0" width="100%" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" class="c4">Simrad, Inc</td>
<td width="33%" class="c11"><? echo date("F d, Y ");
?></td>
<td width="33%" class="c5"><? echo date("g:i a");
?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table summary="" class="c7" align="center"
cellpadding="5"
cellspacing="0">
<tr>
<td colspan="2" class="c9">Simrad, Inc :: Show Schedule :: Edit
Confirmation</td>
</tr>
</table>
<table summary="" class="c7" border="0" cellpadding="5"
cellspacing="0"
width="90%">
<?php
// include the methods
include("showlister_methods.inc.php");
// parse the $_POST vars into something useful
// also check for nulls
$the_id = $_POST['show_id'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$emonth = $_POST['e_month'];
$eday = $_POST['e_day'];
$eyear = $_POST['e_year'];
if ($_POST['venue']) {
$venue = $_POST['venue'];
} else {
die_now("<h3>Sorry</h3><p>Show is a required field. Use your
browser 'back' button to fix this.</a></p>");
}
if ($_POST['location']) {
$location = $_POST['location'];
} else {
die_now("<h3>Sorry</h3><p>Location is a required field. Use your
browser 'back' button to fix this.</a></p>");
}
$details = $_POST['details'];
$the_artist_id = $_POST['artist'];
// echo("the_artist_id: $the_artist_id");
?>
<html>
<body>
<?php
// read in the connection settings
require("showlister_settings.inc.php");
// connect to the RDBMS
$db = mysql_connect("$site","$user","$pass")
or die_now("<h2>Could not connect to database server</h2><p>Check
passwords and sockets</p>");
// select the database
mysql_select_db("$database",$db)
or die_now("<h2>Could not select database $database</h2><p>Check
database name</p>");
// update the database record
$result = mysql_query("update $database_table
set month='$month', day='$day', year='$year',
e_month='$emonth',
e_day='$eday', e_year='$eyear', venue='$venue',
location='$location',
details='$details', artist_id='$the_artist_id'
where show_id = '$the_id'",$db)
or die_now("<h2>Could not change show</h2>");
// echo out a status report and show id
//echo("<div class='box'>\n\t<h3>showlister :: edit
show</h3>\n</div>\n");
echo("<div class='box'>show (id='$the_id')
updated</div>\n");
?>
<?php
footer();
?>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------
Now the code for the show list page, which calls the above page for
editing show info -
-------------------------------------------------------------------------------------------------------------------------
<body class=".c1">
<br />
<br />
<table summary="" class="c6" align="center">
<tr>
<td>
<table summary="" border="0" width="100%" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" class="c4">Simrad, Inc</td>
<td width="33%" class="c11"><? echo date("F d, Y ");
?></td>
<td width="33%" class="c5"><? echo date("g:i a");
?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table summary="" class="c7" align="center"
cellpadding="5"
cellspacing="0">
<tr>
<td colspan="2" class="c9">Simrad, Inc :: Show Schedule :: Edit</td>
</tr>
</table>
<table summary="" class="c7" border="0" cellpadding="5"
cellspacing="0"
width="90%">
<?php
// read in the connection settings
require("showlister_settings.inc.php");
// connect to the RDBMS
$db = mysql_connect("$site","$user","$pass")
or die_now("<h2>Could not connect to database server</h2><p>Check
passwords and sockets</p>");
// select the database
mysql_select_db("$database",$db)
or die_now("<h2>Could not select database $database</h2><p>Check
database name</p>");
// query for the show selected for editing in manage_shows.php
$result = mysql_query("select *
from $database_table where show_id = '$the_id'",$db)
or die_now("<h2>Could not echo show to be edited</h2>");
// echo the show into an editing form
while($row = mysql_fetch_array($result)) {
$the_month = $row["month"];
$the_day = $row["day"];
$the_year = $row["year"];
$the_emonth = $row["e_month"];
$the_eday = $row["e_day"];
$the_eyear = $row["e_year"];
$the_location = $row["location"];
$the_details = $row["details"];
$the_venue = $row["venue"];
$the_artist_id = $row["artist_id"];
echo("<div class=\"box\"><h3>Show Schedule :: Edit
Shows</h3></div>
<div class=\"box\">
<form method=\"post\" action=\"edit_shows_02.php\">
<table border=\"1\" width=\"80%\">
<tr>
<td>Show ID</td>
<td>Company ID</td>
<td>Month</td>
<td>Day</td>
<td>Year</td>
<td>Ending Month</td>
<td>Ending Day</td>
<td>Ending Year</td>
<td>Show</td>
<td>Location</td>
</tr>
<tr>
<td><b>$the_id</b></td>
<td><input type=\"text\" name=\"artist\"
value=\"$the_artist_id\" size=\"2\"></input></td>
<td><input type=\"text\" name=\"month\"
value=\"$the_month\" size=\"2\"></input></td>
<td><input type=\"text\" name=\"day\"
value=\"$the_day\" size=\"2\"></input></td>
<td><input type=\"text\" name=\"year\"
value=\"$the_year\" size=\"4\"></input></td>
<td><input type=\"text\" name=\"emonth\"
value=\"$the_emonth\" size=\"2\"></input></td>
<td><input type=\"text\" name=\"eday\"
value=\"$the_eday\" size=\"2\"></input></td>
<td><input type=\"text\" name=\"eyear\"
value=\"$the_eyear\" size=\"4\"></input></td>
<td><input type=\"text\" name=\"venue\"
value=\"$the_venue\" size=\"12\"></input></td>
<td><input type=\"text\" name=\"location\"
value=\"$the_location\"></input></td>
</tr>
</table><br>
<input type=\"hidden\" name=\"show_id\"
value=\"$the_id\">
<input type=\"submit\" value=\"update show\">
</form>
</div>");
}
// for now, list table of artist ids + artist names
// later, we'll echo it into a select box
// connect to the RDBMS
$db = mysql_connect("$site","$user","$pass")
or die_now("<h2>Could not connect to database server</h2><p>Check
passwords and sockets</p>");
// select the database
mysql_select_db("$database",$db)
or die_now("<h2>Could not select database $database</h2><p>Check
database name</p>");
// query for the artist ids and anems
$result = mysql_query("select artist_id, artist_name
from $database_table_artists
order by artist_name",$db)
or die_now("<h2>Could not echo artists table</h2>");
// echo the results
echo("<div class='box'><b>artist ids and
names</b><br>");
while($row = mysql_fetch_array($result)) {
$the_artist_id = $row["artist_id"];
$the_artist_name = $row["artist_name"];
echo("$the_artist_id" . " = " . "$the_artist_name" .
"<br>\n");
}
echo("</div>");
?>
<br /><br />
<?php
footer();
?>
</body>
</html>