I'm running MySQL 4.1.14, PHP 5.04, and Apache 2.0.54 on Windows XP Pro Service
Pack 2. I have text data in char fields in MySQL.
I have a problem trying to edit a record and store the data back in the mysql
table. I start by displaying all fields from the record in a form. The file
that displays the data for editing is called edit_bird.php. It is called using
the following syntax:
<p>Would you like to <a href=\"edit_bird.php?bird_id=$bird_id\">edit this
entry</a>?</p>
Here's where I call the fields from the birds file.
$get_bird = "select bird_id, c_species, c_genus, l_species, l_genus, date_seen,
location, city, state, number, backyard, spring, summer, fall, winter, notes
from birds where bird_id = $_GET[bird_id]";
$get_bird_res = mysql_query($get_bird,$conn) or die(mysql_error());
I then define variables to hold the data - here's the beginning of the block.
$bird_id = mysql_result($get_bird_res,0,'bird_id');
$c_genus = stripslashes(mysql_result($get_bird_res,0,'c_genus'));
$c_species = stripslashes(mysql_result($get_bird_res,0,'c_species'));
I then display the data by building a variable to hold the html form which is
then echoed to the screen. I've added bird_id to the form for troubleshooting.
This data displays correctly. Here's the beginning of the block.
$display_block = "
<form method=post action='do_editbird.php'>
<table>
<tr>
<td align='right'>
<strong>Bird ID: </strong>
</td>
<td align='left'>
<input type='text' name='bird_id' size=40 maxlength=150
value='$bird_id' disabled>
</td>
</tr>
<tr>
<td align='right'>
<strong>Common Name, Genus: </strong>
</td>
<td align='left'>
<input type='text' name='c_genus' size=40 maxlength=150
value='$c_genus'>
</td>
</tr>
I close the block with a submit button, which calls do_editbird.php, which
executes the following code.
$edit_bird = "update birds set c_species = '$_POST[c_species]',
c_genus = '$_POST[c_genus]', l_species = '$_POST[l_species]',
l_genus = '$_POST[l_genus]', date_seen = '$_POST[date_seen]',
location = '$_POST[location]', city = '$_POST[city]',
state = '$_POST[state]', number = '$_POST[number]',
backyard = '$_POST[backyard]', spring = '$_POST[spring]',
summer = '$_POST[summer]', fall = '$_POST[fall]',
winter = '$_POST[winter]', notes = '$_POST[notes]' where bird_id =
'$_POST[bird_id]'";
mysql_query($edit_bird,$conn) or die(mysql_error());
The data is not written to the MySQL file. The following error is in the
error.log file in the Apache logs directory:
[client 127.0.0.1] PHP Notice: Undefined index: bird_id in C:\\apps\\Apache
Group\\Apache2
\\htdocs\\php\\lifelist\\do_editbird.php on line 21, referer:
http://localhost/php/lifelist/edit_bird.php?bird_id=68
When I change the where clause of $edit_bird as shown below, the data IS
written back to the MySQL file.
winter = '$_POST[winter]', notes = '$_POST[notes]' where bird_id = 82";
So clearly the where clause is not picking up a value from '$_POST[bird_id]'.
I've tried every variant I can think of so the right
side of the where clause resolves to a value to no avail. At this point, nearly
any suggestion is welcome.
Thanks!
Jim Tyler
[Non-text portions of this message have been removed]
The php_mysql group is dedicated to learn more about the PHP/MySQL web database
possibilities through group learning.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php_mysql/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/