update upon submit<

OK I have this script


<html>
<BODY bgcolor="#000000" text="#DB0700" link="orange" vlink="orange">

<?php
$db = mysql_connect("localhost", "name", "pass");
mysql_select_db("skafreaks",$db);
$art=$_GET["art"];
$art=ereg_replace("%20", " ", $art);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE bios SET artist='$artist',bio='$bio' WHERE id=$id";
} else {
$sql = "INSERT INTO bios (artist,bio) VALUES ('$artist','$bio')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p><a href='http://www.htmlforums.com/archive/index.php/1bio.php?art=$artist'>Back To Edit News</a>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM bios WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p><a href='http://www.htmlforums.com/archive/index.php/1bio.php?art=$artist'>Back To Edit News</a>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM bios WHERE artist='$art'",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=http://www.htmlforums.com/archive/index.php/\"%s?id=%s\">%s</a> \n", $PHP_SELF, $myrow["id"], $myrow["bio"]);
printf("<a href=http://www.htmlforums.com/archive/index.php/\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>

<form method="post" action="<?php echo $PHP_SELF?>">

<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM bios WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$artist = $myrow["artist"];
$bio = $myrow["bio"];
// print the id for editing
?>

<input type=hidden name="id" value="<?php echo $id ?>">

<?php
}
?>

<input type="hidden" name="artist" value="<?php echo $art ?><?php echo $artist ?>" size="100"><br>
Bio:<br><TEXTAREA name="bio" rows="10" cols="100"><?php echo $bio ?></TEXTAREA><br>
<input type="Submit" name="submit" value="Enter information">
</form>



<?php
}
?>

</body>
</html>

the way it works is there is a form and you can add new records or update records by clicking one of them.
I want it so they don't have to click a link to edit it.
I have the database which has id, bio, & artist in it. I want it so the bio automatically shows up for the artist. (artist = $art which is sent in the link to the page)

hope you can understand what I'm asking.

Thanks For Any Helpumm no, I do not understand

you don't have anyhtin to update. it is all hidden elements. if you want them to update it then give them something to update.ok sorry. I guess I had the question better the first time (then I changed it) but anyways. All I really want to do is have the bio automatically show up for that artist in a text box and then when they edit it and click submit it updates it.
thats all I really need. I was just using that script and thought it might be easier to work with that.
All I really need to figure out is how to work the UPDATE into it (im not sure how to do that)what is wrong with what you have? it should work but haven't tried it. just change this to regular text field.

<input type="hidden" name="artist" value="<?php echo $art ?><?php echo $artist ?>" size="100">

besides, you can't set a size to a hidden element anyway.well the artist isn't the problem it's the bio. I want the bio to show up automatically and then update when they change it. The artist is hidden so they can't edit that.if you don't want artist updated take it out of the update query.

also

<TEXTAREA name="bio" rows="10" cols="100"><?php echo $bio ?></TEXTAREA><br>

what is wrong with that? it should show just like you have it.

again, did you run it and what errors if any did you get?Scoutt I want to thank you for trying to help but I don't think you understand what I am trying to do. So let me try to explain it over again.

The problem isn't with that script. The script works fine, but it doesn't work the way I want it to. The way I have the script setup is when someone goes to the page it will be from a link bio.php?art=artist

that will enter in the artist info. then it will show a list of all the bios for that artist. Then they click one to edit it. It gets edited and updated by the id number. The way it is setup they can enter in multiple bios for their band.
The submit artist is there in case they haven't yet added a bio. then it will submit $art as the artist name.
The problem is that there should only be one bio for each artist. So when they come to the page instead of clicking a link if they have already entered a bio it should appear in the textarea automatically. Then update for that artist automatically.

So I tryed putting the bio in with a printf and it would show up fine but then it would just add another bio to the list instead of updating the one that already exists.
Thats also why I said maybe it would be easier to just start from scratch and learn how to do just an update script for the bio.

I'm really sorry if you don't understand this, but I really really really appreciate all your help!this is what I see that script doing.

bio.php?art=artist

you send that link to the script it will not populate the textarea as you are looking for an ID. not artist. I see where you have the printf and those aren't really needed. I also don't see how you get multiple bios for 1 artist. that script will update not add more. if you don't want to add more than take the insert out.

are you trying to submit from a link? why do you have the bio in that link as well? just send the id.

I still don't understand. move the textarea in with the if statement and the hidden inputs. tha tiwll stop the extra bios.

<html>
<BODY bgcolor="#000000" text="#DB0700" link="orange" vlink="orange">

<?php
$db = mysql_connect("localhost", "name", "pass");
mysql_select_db("skafreaks",$db);
$art=$_GET["art"];
$art=ereg_replace("%20", " ", $art);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE bios SET artist='$artist',bio='$bio' WHERE id=$id";
} else {
$sql = "INSERT INTO bios (artist,bio) VALUES ('$artist','$bio')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p><a href='http://www.htmlforums.com/archive/index.php/1bio.php?art=$artist'>Back To Edit News</a>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM bios WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p><a href='http://www.htmlforums.com/archive/index.php/1bio.php?art=$artist'>Back To Edit News</a>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM bios WHERE artist='$art'",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=http://www.htmlforums.com/archive/index.php/\"%s?id=%s\">%s</a> \n", $PHP_SELF, $myrow["id"], $myrow["bio"]);
printf("<a href=http://www.htmlforums.com/archive/index.php/\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>

<form method="post" action="<?php echo $PHP_SELF?>">

<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM bios WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$artist = $myrow["artist"];
$bio = $myrow["bio"];
// print the id for editing
?>

<input type=hidden name="id" value="<?php echo $id ?>">
<input type="hidden" name="artist" value="<?php echo $art ?><?php echo $artist ?>" size="100"><br>
Bio:<br><TEXTAREA name="bio" rows="10" cols="100"><?php echo $bio ?></TEXTAREA><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}

}
?>

</body>
</html>well, that still doesn't get it working the way I wanted it to but since I have no idea how to do it otherwise it will work.

Thanks A Lot!!!!!
 
Back
Top