Right - dollar sign - gotit. That fixed that problem, but there were others so I decided to just abandon this particular address book.
This address book used relational tables. The tables that made up this address book included:
- name (master)
- address
- telephone
- fax
- email
- note
It worked fine. You could - create a record, view a record, add to a record or delete a record, but you could not edit a record without physically going into MySQL and manually altering the entry. It screamed for an edit.php script, which I tried to create, but it proved too problematic due to it involving relational tables.
I like the simplicity of this address book and the clean layout, so I decided to make an address book based on this one. First thing was "Keep it Simple", which meant using just one table. I have it up and running and everthing works fine, except...
But this little problem is on an added feature that I could do without.
I have a regular edit page that displays all the entries and you click on the one you want to edit. It populates the fields, you make your changes, click Submit and BAM - it's done.
The added feature is when you're viewing an entry it has on the bottom the option of "edit this entry", which is linked to a different edit page (big code below).
It doesn't make the changes and when I hit Submit - the page reloads with the fields blank and with this error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... on line 27
and this is line 27:
$myrow = mysql_fetch_array($result);
Like I said, this is just an added feature that I would like to have if it's an easy fix. Thanks.
David P.
The big code:
<?php
$conn = mysql_connect("localhost","username","password");
mysql_select_db("db",$conn) or die( "Unable to select database");
$id = $_GET["id"];
$sql = "SELECT * FROM my_addresses WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<h3 align="center">Edit Record for <span style="color:red"><u><?php echo $myrow['first'] ?> <?php echo $myrow['last'] ?></u></span></h3>
<br />
<center>
<table width="95%" cellspacing=0 cellpadding=3 border=0>
<tr>
<td>
<form method="post" action="<?php echo $PHP_SELF?>" >
<input type=hidden name="id" value="<?php echo $myrow['id'] ?>">
Last Name:<br />
<input type="text" size="35" name="last" VALUE="<?php echo $myrow['last'] ?>">
<br />
<br />
First Name:<br />
<input type="text" size="35" name="first" VALUE="<?php echo $myrow['first'] ?>">
<br />
<br />
Street Address:<br />
<input type="text" size="45" name="address" VALUE="<?php echo $myrow['address'] ?>">
<br />
<br />
City / State / Zipcode:<br />
<input type="text" size="35" name="city" VALUE="<?php echo $myrow['city'] ?>">
<input type="text" size="2" name="state" VALUE="<?php echo $myrow['state'] ?>">
<input type="text" size="10" name="zipcode" VALUE="<?php echo $myrow['zipcode'] ?>">
<br />
<br />
Home Phone:<br />
<input type="text" size="35" name="home_phone" VALUE="<?php echo $myrow['home_phone'] ?>">
<br />
<br />
Work Phone:<br />
<input type="text" size="35" name="work_phone" VALUE="<?php echo $myrow['work_phone'] ?>">
<br />
<br />
Cell Phone:<br />
<textarea name="cell_phone" cols=45 rows=5 wrap=virtual><?php echo $myrow['cell_phone'] ?></textarea>
<br />
<br />
Email:<br />
<input type="text" size="65" name="email" VALUE="<?php echo $myrow['email'] ?>">
<br />
<br />
Personal Notes:<br />
<textarea name="notes" cols=45 rows=5 wrap=virtual><?php echo $myrow['notes'] ?></textarea>
<br />
<br />
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="Submit">
</form>
</td>
</tr>
</table>
</center>
<?php
if ($_POST['$submit'])
{
$id = $_POST['id'];
$last = $_POST['last'];
$first = $_POST['first'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$home_phone = $_POST['home_phone'];
$work_phone = $_POST['work_phone'];
$cell_phone = $_POST['cell_phone'];
$email = $_POST['email'];
$notes = $_POST['notes'];
$sql = "UPDATE my_addresses SET last='$last', first='$first', address='$address', city='$city', state='$state', zipcode='$zipcode', home_phone='$home_phone', work_phone='$work_phone', cell_phone='$cell_phone', email='$email', notes='$notes' where id = $id";
$result = mysql_query($sql);
echo "
<br />
<br />
<p align=\"center\"><span style=\"color:red\">Information updated.</span></p>
<br />
<br />
";
}
?>