dangeorge6 Posted February 19, 2007 Share Posted February 19, 2007 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!!! Quote Link to comment Share on other sites More sharing options...
ataria Posted February 19, 2007 Share Posted February 19, 2007 You need to make the Profile_Id a Primary Key, and Auto_Increment. :] Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 19, 2007 Share Posted February 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 19, 2007 Author Share Posted February 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 19, 2007 Author Share Posted February 19, 2007 Poco, Yeah it is defined prior to this, when the user logs in to my site. Quote Link to comment Share on other sites More sharing options...
marcus Posted February 19, 2007 Share Posted February 19, 2007 Try putting tick (`) marks around some of the fields. Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 19, 2007 Author Share Posted February 19, 2007 you mean like... INSERT INTO $SQL_MP3_TABLE ('profile_id' etc... that didn't work. :'( Quote Link to comment Share on other sites More sharing options...
marcus Posted February 19, 2007 Share Posted February 19, 2007 No. $query = "INSERT INTO (`field1`,`field2`) VALUES('$field1data','$field2data')"; Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 19, 2007 Author Share Posted February 19, 2007 no luck with the ` what does that do anyway? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 19, 2007 Share Posted February 19, 2007 The ` is like putting quotation marks around something. It is saying THAT is what it is. You have one of your fields named "time"...time is a predefined PHP variable, so without the ticks (`) around it PHP may get confused on what you mean. So the ticks are useful in cases like that. Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 19, 2007 Author Share Posted February 19, 2007 thanks. time works for some reason. Problem is still UNRESOLVED though, any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 20, 2007 Author Share Posted February 20, 2007 bump ??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 Don't put quotes around $profile_id if it's a number. That makes it into a string. Quote Link to comment Share on other sites More sharing options...
skali Posted February 20, 2007 Share Posted February 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.