954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php script


<?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 'Please enter the track\'s name!


';
}

// 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 'The file has been uploaded!


';

} else { // Couldn't move the file over.
echo 'The file could not be moved.


';
$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 = 'Size information not available.';
}

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


';
//}

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

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


';
}

// 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 'Please enter the artist\'s name!


';
}

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


';
}

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 'The print has been added.


';
} else { // If the query did not run OK.
echo 'Your submission could not be processed due to a system error.


';
}

} else { // Failed a test.
echo 'Please click "back" and try again.


';
}

} else { // Display the form.
?>



Fill out the form to create a Track:

Track Name:

Track: The file name should not include spaces or other invalid characters and should have a file extension.

Artist:

Existing =>
Select One

<?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 "{$row['name']}\n";
}
mysql_close(); // Close the database connection.
?>


New =>
Artist Name:

Genre:

Existing =>
Select One
<?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 "{$row['name']}\n";
}
mysql_close(); // Close the database connection.
?>

Label:

Track credits :






<?php
} // End of main conditional.
?>

Brims
Light Poster
44 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

Your select statement needs to be terminated with a semi-colon (inside the quotes).

$query = "SELECT genre_id, (genre_name) AS name FROM track_genre ORDER BY genre_name ASC;";

phpstan
Newbie Poster
14 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

you can just remove the ASC from the query.
it sorts by ascending by default

metalix
Posting Whiz in Training
218 posts since Mar 2010
Reputation Points: 13
Solved Threads: 34
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You