I've been looking at Sitepoint for a few days now. Very nice site. Lots of good information. Keep up the good work!!!
I am trying my hand at PHP/mySQL for the first time. I followed Kevin Yank's tutorial and learned a great deal. I've got everything working but one item. I have a form on my site with a <SELECT> populated by PHP from a mySQL database. For some reason, the VALUE always ends up being the last record in the array, not the value that is selected. As far as I can tell I coded everything correctly. Can someone please look at my code below and tell me what I'm doing wrong. I greatly appreciate it. Thank you.
$sql = "INSERT INTO CD_Info SET " .
"Artist_ID*='$artistdd', Title='$Title', Year='$year', Genre='$genre',original='$original', Date_Added=CURDATE()";
if (mysql_query($sql)) {
echo( "<P>CD has been added.</P>");
} else {
echo( "<P>Error adding CD: " .
mysql_error() . "</P>");
}
}
?>
BTW - This is basically a CD Collection database. I am trying to get the correct artist in with the correct CD title by inserting the Artist_ID in the CD_Info table.
DUH! I figured it out. I made the variable $artistdd = artist.id_artist. $artistdd is also the name of my control on my form. Of course this will make it not work. I change the variable to $artistid and it works. Thanks to anyone who looked at this. The correct and working version is copied below.
<select size="1" name="artistdd" tabindex="1">
<OPTION SELECTED VALUE ="">Select One
<OPTION VALUE="">----------
<?php
while ($artist = mysql_fetch_array($artists)) {
$artistid = $artist[ID_Artist];
$aname = $artist[Name];
echo( "<OPTION VALUE='$artistid'>$aname\n");
}
Bookmarks