First off, thank you to all who have helped me with my initial problem last week. I feel that I am at the cusp of understanding the lines of code, rather than copying and pasting and praying 🙂
Today's problem is this... My little script, which I use to add a song name and an artist, works! When I add a new song and artist and click submit, they display correctly on the next page and the data saves correctly to the database. The problem lies in when I use the drop down box to select an artist previously added in, the artist is not displayed on the 2nd page, and the artist data is not saved to the database. The song is there, but the artist is not.
Questions:
What is wrong with my scripts which prevents the drop-down menu from correctly adding in the artist?
Why does the selection of an artist in the drop down menu automatically send me to the next page, rather than waiting for me to click the SUBMIT button?
What do I do to prevent duplicate entries?
Below are my two scripts, as edited with the help of the board (Thanks again!)
makemusic.php (This is where I enterthe song/artist)
<html>
<head>
<title>Add</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
$connect= mysql_connect("localhost","root","cpyter")
or die("Could not connect to database in localhost !");
$result=mysql_select_db("music")
or die("Could not select music database !");
?>
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0" height="277">
<tr>
<td bgcolor="#000000" height="2">
<div align="center"><b><font color="#FFFFFF">ADD A RECORD</font></b></div>
</td>
</tr>
<tr>
<td width="48%" height="121" bgcolor="#CCCCCC">
<form name="form1" method="post" action="makemusic1.php">
<table width="75%" border="0" align="center">
<tr>
<td width="36%"><b> Name</b></td>
<td width="64%">
<div align="center">
<input type="text" name="songname" size="20">
</div>
</td>
</tr>
<tr>
<td colspan=2>
<div align="center">
<select name="artist" tabindex="4" onChange=submit()>
<option value="notset">- or select an artist -</option>
<?
//--- CREATE ARTIST SELECT ---
$sql = "SELECT DISTINCT groupname FROM songs ORDER BY groupname";
$groupname = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($groupname)) {
echo '<option value="' . $row['groupname'] . '">' . $row['groupname'] . '</option>';
}
?>
</select>
</div>
</td>
</tr>
<tr>
<td width="36%"><b>Group</b></td>
<td width="64%">
<div align="center">
<input type="text" name="groupname" size="20">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit22" value="Submit" action="required">
</div>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
makemusic1.php (This is the page that displays the newly-entered song/artist)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$connect= mysql_connect("localhost","root","cpyter")
or die("Could not connect to database in localhost !");
$result=mysql_select_db("music")
or die("Could not select music database !");
$sqlquery = "INSERT INTO songs VALUES('','". $songname ."','". $groupname ."')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query !");
echo "<table border=1 align=center width=500>";
echo " <tr> ";
echo " <td> ";
echo " Song Name";
echo " </td>";
echo " <td>".$songname. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Group";
echo " </td>";
echo " <td >".$groupname. "</td>";
echo " </tr>";
//echo " <tr> ";
//echo " <td > ";
//echo " Song ID";
//echo " </td>";
//echo " <td>".$songid. "</td>";
//echo " </tr>";
//echo " <tr> ";
//echo " <td colspan=2> ";
//echo " Add another record <a href="http://localhost/info/makemusic.php">LINK</a>";
//echo " </td>";
//echo " </tr>";
echo "</table>";
?>
Add another record <a href="http://localhost/info/makemusic.php">LINK</a>
</body>
</html>