infantigniter Posted March 1, 2008 Share Posted March 1, 2008 Call me crazy, but I cannot find out what's wrong with this script. Its function is to take the form values and post them to a database called 'games'. The pictures (two fields) both upload fine, onto the server. However nothing is being added to the database, even though no errors are showing. Here's the script: function MySQLDB(){ /* Make connection to database */ $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); $q1 = "SELECT MAX(G_ID) FROM ".TBL_GAMES.""; $result1 = mysql_query($q1); $gid = $result1++; if (!$q1) { $message0 = 'Invalid query: ' . mysql_error() . "\n"; $message0 .= 'Whole query: ' . $query; die($message0); } if (!$result1) { $messagex = 'Invalid query: ' . mysql_error() . "\n"; $messagex .= 'Whole query: ' . $query . "Here's gid: $gid \n"; die($messagex); } $q2 = "INSERT INTO zendscom_zendogames.games (G_ID, G_NAME, G_IMGURL, G_CAT, G_URL, G_YMAL, G_BASEQUICK, G_DESC, G_PUB) VALUES ('$gid','$gametit','$addimg','$genre','$addswf','$ymal','$bq','$desc','$pub')"; $result2 = mysql_query($q2); if (!$q2) { $message1 = 'Invalid query: ' . mysql_error() . "\n"; $message1 .= 'Whole query: ' . $query . "\n"; die($message1); } if (!$result2) { $message2 = 'Invalid query: ' . mysql_error() . "\n"; $message2 .= 'Whole query: ' . $query; die($message2); }} That's where the errors are, I believe. Surplus code from above that: $gametit=$_POST[gametit]; $genre=$_POST[genre]; $ymal=$_POST[ymal]; $desc=$_POST[desc]; $pub=$_POST[publisher]; $bq=$_POST[basequick]; //UPLOAD SCRIPT STUFF /*for game*/ while(list($key,$value) = each($_FILES['games']['name'])) { if(!empty($value)){ $fileswf = $gametit.$value; $addswf = "kittens/siamese/$fileswf"; copy($_FILES[games][tmp_name][$key], $addswf); chmod("$addswf",0777); }} //for image while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)){ $fileimg = $gametit.$value; $addimg = "kittens/siamese/avaria/$fileimg"; copy($_FILES[images][tmp_name][$key], $addimg); chmod("$addimg",0777); }} However that part seems to work fine. Can anybody figure out what's going wrong here??? (DB_USER, etc. are all defined in an "included" constants php file, which functions fine with the login/registration scripts I use. In fact the registration scripts are almost identical to this, and work!) Thank you. Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 Well, for starters $result1 is a result resource as returned by mysql_query, no point try to increment it as you do here... $gid = $result1++; I can see plenty else wrong with this code. are you sure you have error_reporting turned on and display_errors enabled? Quote Link to comment Share on other sites More sharing options...
infantigniter Posted March 1, 2008 Author Share Posted March 1, 2008 I removed the $gid part as you said, as well as it being called in the INSERT INTO script. I have the G_ID row on auto_increment so that column should work anyhow. Also, I removed all mention of $q1 and $result1. Both things you mentioned are turned on. If it sheds any light, I was using a different error reporting method before and it printed errors for q2 and result2 but not anything else. Quote Link to comment Share on other sites More sharing options...
infantigniter Posted March 1, 2008 Author Share Posted March 1, 2008 I still need help with this... Quote Link to comment Share on other sites More sharing options...
infantigniter Posted March 1, 2008 Author Share Posted March 1, 2008 I know it's a simple solution. Someone please enlighten me Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted March 2, 2008 Share Posted March 2, 2008 You have to do this stuff: $gametit=$_POST[gametit]; $genre=$_POST[genre]; $ymal=$_POST[ymal]; $desc=$_POST[desc]; $pub=$_POST[publisher]; $bq=$_POST[basequick]; before the INSERT INTO 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.