Mustang Evolution Forum banner

1 - 19 of 19 Posts

·
Banned
Joined
·
11,872 Posts
Discussion Starter #1
PHP:
if ($_POST['do'] == 'insertartists')
{

	$vbulletin->input->clean_array_gpc('p', array(
		'artist' => TYPE_NOHTML,
		'artistdesc' => TYPE_STR,
	));
	
	$artist = $vbulletin->GPC['artist'];
	$artistdesc = $vbulletin->GPC['artistdesc'];

	$db->query_write("INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist, artistdesc) VALUES ('" . $db->escape_string($artist)  . "', '" . $db->escape_string($artistdesc) . "')"); 
	
	$vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addartists";
	eval(print_standard_redirect("You have successfully added a Artist.", false, true));
}
I am writing a Music Lyrics Database Script that intergrates into vBulletin. That code above is used to add a new Artist to the Database. Do you see anything in it that would case a blank page after submitting the data? I can't find anything however every time I try to add a new artist I submit it and it doesn't do anything but return a blank page. The information is not added to the database.

This is the html for it:

Code:
<form action="http://www.exposethemusic.net/lyrics/adminlyrics.php?do=insertartists" method="post" >
<table class="tborder" cellpadding="5" cellspacing="0" width="100%" border="0" align="center">
<tr>
<td class="tcat" colspan="2">Add Artists</td>
</tr>
<tr>
<td class="alt1" width="40%">Artist/Band Name</td>
<td class="alt2" width="60%"><input type="text" class="bginput" name="artist" size="50" maxlength="100" value="" /></td>
</tr>
<tr valign="top">
<td class="alt1" width="20%">Artist Description<br /><dfn>Give a good description of the artist. A good source of information would be the artists official page or Amazon.com.</dfn></td>
<td class="alt2"><textarea name="artistdesc" rows="20" cols="70"></textarea>
</td>
</tr>
<tr>
<td class="alt1" colspan="2" align="center"><input type="submit" class="button" value="$vbphrase[submit]" /></td>
</tr>
</table>
</form>
 

·
15.3 Second V8 Killer Yo
Joined
·
7,212 Posts
Do have a table prefix configured? If so, what is it?

Is there a Show last error type method inside VB's db class? If so, put that in there to see if something blew up in the insert.
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #3
No Table Prefix. That is just used for when I distribute the hack and other people have one.

There are these two:
$db->error() will return the Error Text for the most recent database operation.
$db->errno() will return the Error Number for the most recent database operation.
I added them like so:
PHP:
if ($_POST['do'] == 'insertartists')
{

    $vbulletin->input->clean_array_gpc('p', array(
        'artist' => TYPE_NOHTML,
        'artistdesc' => TYPE_STR,
    ));
    
    $artist = $vbulletin->GPC['artist'];
    $artistdesc = $vbulletin->GPC['artistdesc'];

    $db->query_write("INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist, artistdesc) VALUES ('" . $db->escape_string($artist)  . "', '" . $db->escape_string($artistdesc) . "')"); 
    $db->err();
    $db->errno();
    $vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addartists";
    eval(print_standard_redirect("You have successfully added a Artist.", false, true));
}
Not sure if that is right. It still returns just a blank white page.

I think it's a problem with the php or the form. If it was a database error it should generate a vbulletin mysql error page automatically.
 

·
15.3 Second V8 Killer Yo
Joined
·
7,212 Posts
Now that I am home...the problem isn't with the form per say...

The problem is, you are doing if post[do]...you are no posting any controls named do....you need to use _get[do] because it is part of the query string and not part of the form.

So...right now, it is blank because you are never getting into the if statement. If you want to get in there, either change it to get[do] or add a hidden control to the form that will end up getting posted and remove the ?do= from the form's action.

This will fix it easiest...

if ($_GET['do'] == 'insertartists')
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #6
Added the hidden input :)

New form:
Code:
<form action="http://www.exposethemusic.net/lyrics/adminlyrics.php" method="post" >
<table class="tborder" cellpadding="5" cellspacing="0" width="100%" border="0" align="center">
<tr>
<td class="tcat" colspan="2">Add Artists</td>
</tr>
<tr>
<td class="alt1" width="40%">Artist/Band Name</td>
<td class="alt2" width="60%"><input type="text" class="bginput" name="artist" size="50" maxlength="100" value="" /></td>
</tr>
<tr valign="top">
<td class="alt1" width="20%">Artist Description<br /><dfn>Give a good description of the artist. A good source of information would be the artists official page or Amazon.com.</dfn></td>
<td class="alt2"><textarea name="artistdesc" rows="20" cols="70"></textarea>
</td>
</tr>
<tr>
<td class="alt1" colspan="2" align="center"><input type="submit" class="button" value="$vbphrase[submit]" /></td>
</tr>
</table>
<input type="hidden" name="do" value="insertartists" />
</form>
Same PHP. It worked :woot:
 

·
15.3 Second V8 Killer Yo
Joined
·
7,212 Posts
Added the hidden input :)

New form:
Code:
<form action="http://www.exposethemusic.net/lyrics/adminlyrics.php" method="post" >
<table class="tborder" cellpadding="5" cellspacing="0" width="100%" border="0" align="center">
<tr>
<td class="tcat" colspan="2">Add Artists</td>
</tr>
<tr>
<td class="alt1" width="40%">Artist/Band Name</td>
<td class="alt2" width="60%"><input type="text" class="bginput" name="artist" size="50" maxlength="100" value="" /></td>
</tr>
<tr valign="top">
<td class="alt1" width="20%">Artist Description<br /><dfn>Give a good description of the artist. A good source of information would be the artists official page or Amazon.com.</dfn></td>
<td class="alt2"><textarea name="artistdesc" rows="20" cols="70"></textarea>
</td>
</tr>
<tr>
<td class="alt1" colspan="2" align="center"><input type="submit" class="button" value="$vbphrase[submit]" /></td>
</tr>
</table>
<input type="hidden" name="do" value="insertartists" />
</form>
Same PHP. It worked :woot:

I will be sure to bring you the bill when I get there tomorrow. :good:
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #8
Another question for when you get back :D

PHP:
if ($_POST['do'] == 'insertartists')
{

    	$vbulletin->input->clean_array_gpc('p', array(
        	'artist' => TYPE_NOHTML,
        	'artistdesc' => TYPE_STR,
    	));

    	$artist = $vbulletin->GPC['artist'];
    	$artistdesc = $vbulletin->GPC['artistdesc'];

    	$db->query_write("INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist, artistdesc) VALUES ('" . $db->escape_string($artist)  . "', '" . $db->escape_string($artistdesc) . "')"); 
    	
    	$vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addartists";
    	eval(print_standard_redirect("You have successfully added an Artist.", false, true));

}
I want to make sure that
PHP:
$vbulletin->GPC['artist']
1) Has an artist name entered before submitting (Javascript?) and 2) make sure that the artist name doesn't already exist in the database.

I think I can figure 1 out but 2 I'm not sure how to tackle.
 

·
15.3 Second V8 Killer Yo
Joined
·
7,212 Posts
1 is just some simple javascript validater in the onClick event of the post button. 2 will require a query to see if one exists first, if not, then insert.

Another question for when you get back :D

PHP:
if ($_POST['do'] == 'insertartists')
{

    	$vbulletin->input->clean_array_gpc('p', array(
        	'artist' => TYPE_NOHTML,
        	'artistdesc' => TYPE_STR,
    	));

    	$artist = $vbulletin->GPC['artist'];
    	$artistdesc = $vbulletin->GPC['artistdesc'];

    	$db->query_write("INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist, artistdesc) VALUES ('" . $db->escape_string($artist)  . "', '" . $db->escape_string($artistdesc) . "')"); 
    	
    	$vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addartists";
    	eval(print_standard_redirect("You have successfully added an Artist.", false, true));

}
I want to make sure that
PHP:
$vbulletin->GPC['artist']
1) Has an artist name entered before submitting (Javascript?) and 2) make sure that the artist name doesn't already exist in the database.

I think I can figure 1 out but 2 I'm not sure how to tackle.
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #12
I got it with this code:

PHP:
if ($_POST['do'] == 'insertartists')
{

    	$vbulletin->input->clean_array_gpc('p', array(
        	'artist' => TYPE_NOHTML,
    	));
    
    	$artist = $vbulletin->GPC['artist'];

	// Checking to see if any fields were left blank.
	if ($artist == '')
	{
		// Let's Build The Sidebar and Footer
		eval('$vblyrics_sidebar = "' . fetch_template('vblyrics_sidebar') . '";');
		eval('$vblyrics_footer = "' . fetch_template('vblyrics_footer') . '";');
		$vblyrics_error_message = "The Artist Field is required. Please go back and enter an artist.";
     		eval('print_output("' . fetch_template('vblyrics_error') . '");');
	}
	
	// Let's check to see if the Artist that the user is trying to add doesn't exist. If it does exist give an error.
	$artist_name = $db->query_read("SELECT artist FROM " . TABLE_PREFIX . "vblyrics_artists as vblyrics_artists WHERE artist='$artist'");

	if ($db->num_rows($artist_name))
	{

		// Let's Build The Sidebar and Footer
		eval('$vblyrics_sidebar = "' . fetch_template('vblyrics_sidebar') . '";');
		eval('$vblyrics_footer = "' . fetch_template('vblyrics_footer') . '";');
		$vblyrics_error_message = $vbphrase['vblyrics_artistexistserror'];
     		eval('print_output("' . fetch_template('vblyrics_error') . '");');
	}
	else
	{
	    	$db->query_write("INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist) VALUES ('" . $db->escape_string($artist)  . "')"); 
    	}

    	$vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addartists";
    	eval(print_standard_redirect("You have successfully added an Artist.", false, true));

}
I have a design question as far as the database goes.

Here is how I currently have the database setup:

vBLyrics Artists
Code:
+--------------+------------------+------+-----+---------+----------------+
| Field        | Type             | Null | Key | Default | Extra          |
+--------------+------------------+------+-----+---------+----------------+
| artistid     | int(10) unsigned |      | PRI | NULL    | auto_increment |
| artist       | varchar(100)     |      | MUL |         |                |
| artistrating | int(10) unsigned |      |     | 0       |                |
| views        | int(10) unsigned |      |     | 0       |                |
+--------------+------------------+------+-----+---------+----------------+
vBLyrics Albums
Code:
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| albumid  | int(10) unsigned |      | PRI | NULL    | auto_increment |
| album    | varchar(100)     |      |     |         |                |
| artistid | int(10) unsigned |      | MUL | 0       |                |
| views    | int(10) unsigned |      |     | 0       |                |
+----------+------------------+------+-----+---------+----------------+
vBLyrics_Songs
Code:
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| songid     | int(10) unsigned |      | PRI | NULL    | auto_increment |
| artistid   | int(10) unsigned |      | MUL | 0       |                |
| albumid    | int(10) unsigned |      | MUL | 0       |                |
| song       | varchar(50)      |      |     |         |                |
| songlyrics | mediumtext       |      |     |         |                |
| dateadded  | int(10) unsigned |      | MUL | 0       |                |
| views      | int(10) unsigned |      |     | 0       |                |
+------------+------------------+------+-----+---------+----------------+
Those are the three tables I am using as far as getting the actual lyrics up and linked to an artist and a album. I am going for a setup similiar to this: TAYLOR HICKS lyrics When you click on an artists name it will list the artists album name and then the songs on the album.

What I was wanting your opinion on would be the best way to allow me and the members of my Music forum to add lyrics to the site? Right now in my head I have it where they will add the artist, then add an album and link it to the artist and then add a song and link it to an album and artist. That seems like 2 steps too many though.

Is there a easier way that you can see? The thing I can't think up in my head is how I am going to update each table using just one form or whatever. I am racking my brain trying to come up with something easier.
 

·
Premium Member
Joined
·
2,459 Posts
Why can't you let the user add the album and artist at the same time?

When they enter an artist, do a select to see if it's there. If it is, you don't have to touch the artist table. If not, add the artist. Then add them album and link it to the existing artist.

Or... You could even have some sort of selector for the artists that are already there. If they don't find the artist, they click a button to add one. Same for the album and even the song if you want to allow multiple interpretations of a song.
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #14
When they enter an artist, do a select to see if it's there. If it is, you don't have to touch the artist table. If not, add the artist. Then add them album and link it to the existing artist.
Ok I understand that now. If it doesn't exist, run a query to add it to the artist table, if it does exist skip the write query and go on to processing the album and lyrics etc etc.

Thanks.
 

·
Premium Member
Joined
·
2,459 Posts
Ok I understand that now. If it doesn't exist, run a query to add it to the artist table, if it does exist skip the write query and go on to processing the album and lyrics etc etc.

Thanks.
Yeah. Even if the artist is there, I'm sure you'll need the artistid field to match up to the album when you do your select based off the artist they entered. So you'll need to pull that back in your select anyway.

One issue you may want to think about is what to do about people who misspell artist's/album's/song's names when they enter them. You don't want to end up with Metalica and Mettalica and Metallica all in the database...
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #16
Yeah. Even if the artist is there, I'm sure you'll need the artistid field to match up to the album when you do your select based off the artist they entered. So you'll need to pull that back in your select anyway.

One issue you may want to think about is what to do about people who misspell artist's/album's/song's names when they enter them. You don't want to end up with Metalica and Mettalica and Metallica all in the database...
Yea I was thinking about that as well. I am about to look at vBulletin to see how they handle moderating threads.
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #17
Ok so I have been looking through code for hours now and can't come up with a efficient solution to 1) Check the artist, album and song to make sure they do not already exist 2) Get the correct id for all tables.

Right now no information exists in the albums or songs table just the artists table. There are two possible ids that could be used depending on whether or not the artist that I am adding exists or not. If it does already exist then I use that ID. If it doesn't exist then I have to add it and then use that id instead. After I get the correct id I need to first check the album name to make sure it doesn't already exist and if it does exist get the album id for it. If it doesnt exist I need to add the album to the database and get the id for the new album. Then I need to take the albumid and based on whether or not the songname exists for that artist add the song to the database with that albumid.

I wanted to type it out in steps to see if that helped. :lol: I think it may have. So my biggest problem is deciding which id to use with the artist and album tables based on whether or not that artist or album already exists. The song table can only have one outcome and that is for it to not exist for something to happen. If it already exists then there is no point in filling out any of this.

So let's take this in steps. What is the best way to determine which artistid to use and validate it at the same time?

I have been trying to find code that is doing something similar to what I am trying to accomplish but I can't seem to find any.
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #18
I found an approach that works. Setup the tables a bit different and here is the code:

PHP:
if ($_POST['do'] == 'insertsong')
{

    	$vbulletin->input->clean_array_gpc('p', array(
        	'artist' => TYPE_NOHTML,
        	'album' => TYPE_NOHTML,
        	'songname' => TYPE_NOHTML,
        	'songlyrics' => TYPE_NOHTML,
    	));
    
    	$artistname = $vbulletin->GPC['artist'];
    	$albumname = $vbulletin->GPC['album'];
    	$songname = $vbulletin->GPC['songname'];
    	$songlyrics = $vbulletin->GPC['songlyrics'];

	// Checking to see if any fields were left blank.
	if ($artistname == '' OR $albumname == '' OR $songname = '' OR $songlyrics == '')
	{
		// Let's Build The Sidebar and Footer
		eval('$vblyrics_sidebar = "' . fetch_template('vblyrics_sidebar') . '";');
		eval('$vblyrics_footer = "' . fetch_template('vblyrics_footer') . '";');
		$vblyrics_error_message = "You are missing a field. Fix it now. Idiot.";
     		eval('print_output("' . fetch_template('vblyrics_error') . '");');
	}

	$data = $db->query_read("
				SELECT 
				vblyrics_artists.artist AS `artist`,
				vblyrics_songs.song AS `song`
				FROM " . TABLE_PREFIX . "vblyrics_artists AS vblyrics_artists
				LEFT JOIN " . TABLE_PREFIX . "vblyrics_songs AS vblyrics_songs ON vblyrics_artists.artistid = vblyrics_songs.artistid
				WHERE vblyrics_artists.artist='$artist' OR vblyrics_songs.song ='$songname'");

	$validate = $db->fetch_array($data);

	if (is_null($validate['artist']) AND is_null($validate['song']))	
	{
	    	$db->query_write("
			INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist) 
			VALUES ('" . $db->escape_string($artist)  . "')");

		$artistid = $db->insert_id();

	    	$db->query_write("
			INSERT INTO " . TABLE_PREFIX . "vblyrics_songs (artistid, song, songlyrics, album, dateadded) 
			VALUES ('" . $db->escape_string($artistid)  . "', '" . $db->escape_string($songname)  . "', '" . $db->escape_string($songlyrics)  . "', '" . $db->escape_string($albumname)  . "', '" . TIMENOW . "')
		");

		unset($artistid);
	}
	else
	{
 		if($validate['artist'] == $artistname)
		{
			$artistid = $db->query_first("
						SELECT artistid
						FROM " . TABLE_PREFIX ."vblyrics_artists
						WHERE artist = '$artistname'
			");

			$db->query_write("
			INSERT INTO " . TABLE_PREFIX . "vblyrics_songs (artistid, song, songlyrics, album, dateadded) 
			VALUES ('" . $db->escape_string($artistid)  . "', '" . $db->escape_string($songname)  . "', '" . $db->escape_string($songlyrics)  . "', '" . $db->escape_string($albumname)  . "', '" . TIMENOW . "')
			");
		}
    	}

    	$vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addsong";
    	eval(print_standard_redirect("You have successfully added an Artist.", false, true));

}
It's still a bit buggy. It is trying to insert into the artist table even though the artist I used already existed. Got to work on that. It put the rest in the right place though. I think I am going to have to use something other than is_null
 

·
Banned
Joined
·
11,872 Posts
Discussion Starter #19
Improved on that even more:
PHP:
if ($_POST['do'] == 'insertsong')
{

    	$vbulletin->input->clean_array_gpc('p', array(
        	'artist' => TYPE_NOHTML,
        	'album' => TYPE_NOHTML,
        	'songname' => TYPE_NOHTML,
        	'songlyrics' => TYPE_NOHTML,
    	));
    
    	$artistname = $vbulletin->GPC['artist'];
    	$albumname = $vbulletin->GPC['album'];
    	$songname = $vbulletin->GPC['songname'];
    	$songlyrics = $vbulletin->GPC['songlyrics'];

	// Checking to see if any fields were left blank.
	if ($artistname == '' OR $albumname == '' OR $songname = '' OR $songlyrics == '')
	{
		// Let's Build The Sidebar and Footer
		eval('$vblyrics_sidebar = "' . fetch_template('vblyrics_sidebar') . '";');
		eval('$vblyrics_footer = "' . fetch_template('vblyrics_footer') . '";');
		$vblyrics_error_message = "You are missing a field. Fix it now. Idiot.";
     		eval('print_output("' . fetch_template('vblyrics_error') . '");');
	}

	$data = $db->query_read("
				SELECT 
				vblyrics_artists.artist AS `artist`,
				vblyrics_songs.song AS `song`
				FROM " . TABLE_PREFIX . "vblyrics_artists AS vblyrics_artists
				LEFT JOIN " . TABLE_PREFIX . "vblyrics_songs AS vblyrics_songs ON vblyrics_artists.artistid = vblyrics_songs.artistid
				WHERE vblyrics_artists.artist='$artist' OR vblyrics_songs.song ='$songname'");

	$validate = $db->fetch_array($data);

	if($validate['song'] == $songname)
	{
		// Let's Build The Sidebar and Footer
		eval('$vblyrics_sidebar = "' . fetch_template('vblyrics_sidebar') . '";');
		eval('$vblyrics_footer = "' . fetch_template('vblyrics_footer') . '";');
		$vblyrics_error_message = "This Song Already Exists.";
     		eval('print_output("' . fetch_template('vblyrics_error') . '");');
	}
	else
	{
		if ($validate['artist'] != $artistname)	
		{
	    		$db->query_write("
				INSERT INTO " . TABLE_PREFIX . "vblyrics_artists (artist) 
				VALUES ('" . $db->escape_string($artist)  . "')");

			$artistid = $db->insert_id();

	    		$db->query_write("
				INSERT INTO " . TABLE_PREFIX . "vblyrics_songs (artistid, song, songlyrics, album, dateadded) 
				VALUES ('" . $db->escape_string($artistid)  . "', '" . $db->escape_string($songname)  . "', '" . $db->escape_string($songlyrics)  . "', '" . $db->escape_string($albumname)  . "', '" . TIMENOW . "')
			");

			unset($artistid);
		}
		else
		{
 			if($validate['artist'] == $artistname)
			{
				$artistid = $db->query_first("
						SELECT artistid
						FROM " . TABLE_PREFIX ."vblyrics_artists
						WHERE artist = '$artistname'
				");

				$db->query_write("
					INSERT INTO " . TABLE_PREFIX . "vblyrics_songs (
					artistid,
					song,
					songlyrics,
					album,
					dateadded
					) 
					VALUES (
					'" . $db->escape_string($artistid)  . "',
					'" . $db->escape_string($songname)  . "',
					'" . $db->escape_string($songlyrics)  . "',
					'" . $db->escape_string($albumname)  . "',
					'" . TIMENOW . "'
					)
				");
			}
    		}
	}

    	$vbulletin->url = "http://www.exposethemusic.net/lyrics/adminlyrics.php?do=addsong";
    	eval(print_standard_redirect("You have successfully added an Artist.", false, true));

}
Thanks for your help
 
1 - 19 of 19 Posts
Top