All pastes #109726 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-08-01 08:51 UTC
rendered paste body
/* _createAlbumFormat.php */

	require_once("../serv/db.php");
	
	if (!isset($_POST["idParent"]) || !isset($_POST["name"]))
	{
		echo "[{err:\"Invalid Paramaters\", id:0}]";
		exit;
	}
	
	if ( ($album_format = mssql_init("sp_insertAlbumFormat")) )
	{
		mssql_bind( $album_format , "@idParentGenre" , $_POST["idParent"] , SQLINT2 );
		mssql_bind( $album_format , "@name" , $_POST["name"] , SQLVARCHAR );
		mssql_bind( $album_format , "RETVAL" , $idFormat , SQLINT2 );
		
		if ( @mssql_execute($album_format) )
			echo "{id:". $idFormat .", name:\"". addslashes($_POST["name"]) ."\"}";
		else
			echo "{id:0, err:\"Error Occurred: ". addslashes(mssql_get_last_message()) ."\"}";
	}
	
	mssql_close($db);



/* js function */

function create_album_format(idParent, name)
{
	if (name == undefined)
		name = prompt("Insert the name of the album format you wish to create", "");
	
	if (name)
	{
		ajax.open("post", "inc/ajax/_createAlbumFormat.php", true);
		ajax.send("idParent="+ idParent +"&name="+ escape(name));

		ajax.onSuccess = function()
		{
			alert(this.data);
			var obj = eval(this.data);
			if (typeof obj.err == "undefined")
			{
				var f_s = document.getElementById("idFormat");
				
				f_s.options[f_s.options.length] = new Option(obj.name, obj.id);
				f_s.options.sort(options_sort);
			} else
				alert("CGI Error:\n\n"+ obj.err);
		}
	}
}