User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,984 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,958 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2038 | Replies: 0
Reply
Join Date: Nov 2005
Posts: 44
Reputation: Brims is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Brims Brims is offline Offline
Light Poster

php script

  #1  
May 22nd, 2006
Im having problems with this script. Right now it adds everthing to the database if I take this out

[php]
<p><b>Genre:</b>
<p><input type="radio" name="genre" value="existing" /> Existing =>
<select name="existing"> <option>Select One</option>
<?php // Retrieve all the artists and add to the pull-down menu.
$query = "SELECT genre_id, (genre_name) AS name FROM track_genre ORDER BY genre_name ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<option value=\"{$row['genre_id']}\">{$row['name']}</option>\n";
}
mysql_close(); // Close the database connection.
?>
</select>
</p>
[/php]
however i have a track_genre table in my database which is populated with genres. I want to query it to retrieve those values and add the value into the track table in my database track_ genre field I also have a track genre field in my track table. can someone point me in the right direction
[php]




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Add a Print</title>
</head>
<body>
<?php # Script 14.2 - add_print.php
// This page allows the administrator to add a print (product).

require_once ('../mysql_connect.php'); // Connect to the database.

if (isset($_POST['submitted'])) { // Check if the form has been submitted.

// Validate the print_name, image, artist (existing or first_name, last_name, middle_name), size, price, and description.

// Check for a track name.
if (!empty($_POST['track_name'])) {
$tn = escape_data($_POST['track_name']);
} else {
$tn = FALSE;
echo '<p class="red"><font color="red">Please enter the track\'s name!</font></p>';
}

// Check for an image.
if (is_uploaded_file ($_FILES['image']['tmp_name'])) {
if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/{$_FILES['image']['name']}")) { // Move the file over.

echo '<p>The file has been uploaded!</p>';

} else { // Couldn't move the file over.
echo '<p><font color="red">The file could not be moved.</font></p>';
$i = FALSE;
}
$i = $_FILES['image']['name'];
} else {
$i = FALSE;
}

// Check for a size (not required).
if (!empty($_POST['track_label'])) {
$s = escape_data($_POST['track_label']);
} else {
$s = '<i>Size information not available.</i>';
}

// Check for a price.
//if (is_numeric($_POST['price'])) {
// $p = (float) $_POST['price'];
//} else {
//$p = FALSE;
//echo '<p><font color="red">Please enter the print\'s price!</font></p>';
//}

// Check for a description (not required).
if (!empty($_POST['track_credits'])) {
$d = escape_data($_POST['track_credits']);
} else {
$d = '<i>No description available.</i>';
}

if ( ($_POST['genre'] == 'existing') && ($_POST['existing'] > 0)) { // Existing album.
$b = (int) $_POST['existing'];
} else { // No artist selected.
$b = FALSE;
echo '<p><font color="red">Please enter or select the track\'s artist!</font></p>';
}

// Validate the album.
if ($_POST['artist'] == 'new') {

// If it's a new album, add the album to the database.
$query = 'INSERT INTO artist (artist_name) VALUES (';

if (!empty($_POST['artist_name'])) {
$query .= "'" . escape_data($_POST['artist_name']) . "')";
//} else {
//$query .= 'NULL, ';
//}


//if (!empty($_POST['middle_name'])) {
//$query .= "'" . escape_data($_POST['middle_name']) . "', ";
//} else {
// $query .= 'NULL, ';
// }

// Check for a last_name.
//if (!empty($_POST['last_name'])) {
//$query .= "'" . escape_data($_POST['last_name']) . "')";

// Improved MySQL Version:
$result = mysql_query($query);
$a = mysql_insert_id();

/* Standard MySQL Version:
$result = mysql_query ($query); // Run the query.
$a = mysql_insert_id(); // Get the artist ID.
*/

} else { // No last name value.
$a = FALSE;
echo '<p><font color="red">Please enter the artist\'s name!</font></p>';
}

} elseif ( ($_POST['artist'] == 'existing') && ($_POST['existing'] > 0)) { // Existing album.
$a = (int) $_POST['existing'];
} else { // No artist selected.
$a = FALSE;
echo '<p><font color="red">Please enter or select the track\'s artist!</font></p>';
}

if ($tn && $b && $a && $i) { // If everything's OK.

// Add the print to the database.
$query = "INSERT INTO track (artist_id, track_name, track_label, track_genre, track_credits, image_name) VALUES ($a, '$tn', '$s', '$b', '$d', '$i')";
if ($result = mysql_query($query)) { // Worked.
echo '<p>The print has been added.</p>';
} else { // If the query did not run OK.
echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>';
}

} else { // Failed a test.
echo '<p><font color="red">Please click "back" and try again.</font></p>';
}

} else { // Display the form.
?>

<form enctype="multipart/form-data" action="add_track.php" method="post">

<input type="hidden" name="MAX_FILE_SIZE" value="524288"/>

<fieldset><legend>Fill out the form to create a Track:</legend>

<p><b>Track Name:</b> <input type="text" name="track_name" size="30" maxlength="100" /></p>

<p><b>Track:</b> <input type="file" name="image" /> <small>The file name should not include spaces or other invalid characters and should have a file extension.</small></p>

<p><b>Artist:</b>
<p><input type="radio" name="artist" value="existing" /> Existing =>
<select name="existing"><option>Select One</option>

<?php // Retrieve all the artists and add to the pull-down menu.
$query = "SELECT artist_id,(artist_name) AS name FROM artist";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<option value=\"{$row['artist_id']}\">{$row['name']}</option>\n";
}
mysql_close(); // Close the database connection.
?>
</select></p>

<p>
<input type="radio" name="artist" value="new" /> New =>
Artist Name: <input type="text" name="artist_name" size="10" maxlength="75" />
</p>



<p><b>Genre:</b>
<p><input type="radio" name="genre" value="existing" /> Existing =>
<select name="existing"> <option>Select One</option>
<?php // Retrieve all the artists and add to the pull-down menu.
$query = "SELECT genre_id, (genre_name) AS name FROM track_genre ORDER BY genre_name ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<option value=\"{$row['genre_id']}\">{$row['name']}</option>\n";
}
mysql_close(); // Close the database connection.
?>
</select>
</p>

<p><b>Label:</b>
<input type="text" name="track_label" size="30" maxlength="255" /> </p>

<p><b>Track credits :</b>
<textarea name="track_credits" cols="40" rows="5"></textarea></p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit" /></div>
<input type="hidden" name="submitted" value="TRUE" />

</form>
<?php
} // End of main conditional.
?>
</body>
</html>[/php]
Last edited by cscgal : May 22nd, 2006 at 11:02 am.
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC