Jump to content

Why can't I insert value into database! AHHH!


dangeorge6

Recommended Posts

I am utterly stumped.  I need to insert a profile id number into a database and it always inserts '0' instead of the actual number.  I think this may be a mySQL issue, but not sure.  I guarantee you that the session variable has been created prior to this.  My user first hits this page with 'add' as a GET variable:

<?
require('globals.php');
require('functions.php');


if($_GET['action'] == 'add'){

$ber = $_SESSION['profile_id'];
addSongs($ber);

}


?>

I've done tests and I know that the profile_id variable outputs the correct number.

 

Here is functions.php, where the addSongs function is defined:

 

function addSongs($profile_id){
require('globals.php');
require_once('getid3/getid3.php');
//if file uploaded successfully...
if ($_FILES['Filedata']['name']) {


	$uploaddir = '../mp3s/';
	$filename = basename($_FILES['Filedata']['name']);
	$mp3pathname = $uploaddir . $filename;
	  
	if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $mp3pathname)){
	//class to get mp3 id3 info
	$getID3 = new getID3;
	$ThisFileInfo = $getID3->analyze($mp3pathname);
	getid3_lib::CopyTagsToComments($ThisFileInfo);
	$artistID3 = @$ThisFileInfo['comments_html']['artist'][0]; // artist from any/all available tag formats
	$titleID3 = @$ThisFileInfo['comments_html']['title'][0];  // title from ID3v2 
	$albumID3 = @$ThisFileInfo['comments_html']['album'][0];
	$timeID3 = @$ThisFileInfo['playtime_string'];
	if($titleID3 == ""){
	$titleID3 == $filename;
	}  
	//add mp3 info to DB
	$query_addsongs = "INSERT INTO $SQL_MP3_TABLE (profile_id, mp3path, artist, title, album, time)
	VALUES ('$profile_id', '$filename', '$artistID3', '$titleID3', '$albumID3', '$timeID3')";
	mysql_query($query_addsongs) or die(mysql_error());

	}
}

}

 

Everything else INSERTS fine, the profile_id is just always 0!!!!  The profile_id field is an int(10) in the database.  I've even tried casting the variable to int, but no luck. HELP!!!

Link to comment
Share on other sites

It looks like you have the wrong variable name for the profile ID. You are using $profile_id to insert it in the database, the only time I saw you define it is when you put $ber = $_SESSION['profile_id'];

 

Maybe you should try this

 

 


$profile_id = $_SESSION['profile_id'];

$query_addsongs = "INSERT INTO $SQL_MP3_TABLE (profile_id, mp3path, artist, title, album, time)
	VALUES ('$profile_id', '$filename', '$artistID3', '$titleID3', '$albumID3', '$timeID3')";
	mysql_query($query_addsongs) or die(mysql_error());


 

Also what ataria said.

Link to comment
Share on other sites

naw, it's not that kind of id.  It's a number pulled from another table based on the particular user (I do this upon login and save it as the $_SESSION['profile_id'] variable.  It's not a number I need auto generated for this insertion or anything.  Like I said, I've done tests, and I know that this session variable outputs the correct number, it just won't insert for whatever reason.

Link to comment
Share on other sites

try

 

$query_addsongs = "INSERT INTO $SQL_MP3_TABLE (profile_id, mp3path, artist, title, album, time)

VALUES ('{$_SESSION{'profile_id'}}', '$filename', '$artistID3', '$titleID3', '$albumID3', '$timeID3')";

 

and also try printing the query to check if you are properly setting session variables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.