The Little Guy Posted October 21, 2007 Share Posted October 21, 2007 OK, the problem is where I create the $imID and the $imID2. Where it says $row['id'];, it is placing the last number in the database... which it is what I want, but why Is it placing the same id in both $row['id'];? as you may notice, if $twoUp is false, $imID2 should not be set. but if it is true, then $imID2 should be set. <?php $twoUp = FALSE; foreach ($_FILES["file"]["error"] as $key => $error) { //Some more PHP Here //Start of problem mysql_query("INSERT INTO guest_images (`directory`,`file`) VALUES ('$savelocation','$saveFile')"); $sql = mysql_query("SELECT id FROM guest_images WHERE `directory`='$savelocation' AND `file`='$saveFile' LIMIT 1"); $row = mysql_fetch_array($sql); if($twoUp){ $imID2 = '&imageID2='.$row['id']; }else{ $imID2 = ''; } if(!$twoUP){ $imID1 = '?imageID='.$row['id']; if(empty($_FILES['file']['name'][1])){ $twoUp = FALSE; break; }else{ $twoUp = TRUE; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/ Share on other sites More sharing options...
phpknight Posted October 21, 2007 Share Posted October 21, 2007 Can you give a concrete example about what goes in, what you expect to happen (with real values as examples), and then what actually happens? I am not sure I understand the problem exactly from your description, but I am usually pretty good at catching bugs like this. Also, make sure all the loop conditionals, etc., are doing what you expect them to. Sometimes that is the issue. Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-374601 Share on other sites More sharing options...
The Little Guy Posted October 21, 2007 Author Share Posted October 21, 2007 OK... The example: on the home page, the user has two file boxes, so he/she can upload one or two images. next they press upload. $_FILES['file']['name'][1] contains the file name of the image such as: flowers.jpg When It goes through the loop once, $twoUp is set to false. when It gets to the if/else statement (if(empty($_FILES['file']['name'][1])){) that checks to see if there is a second image, if there is, then it sets $twoUp to true, otherwise it sets it to false. That works all fine and dandy, but where it says: $row['id'] it will set them BOTH to the very last ID value in the table (a.ka. the largest value). So... this an example result I am getting: $imID1 = '?imageID=23'; $imID2 = '&imageID2=23'; And this is an example result I am expecting: $imID1 = '?imageID=22'; $imID2 = '&imageID2=23'; I think that covers it all... Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-374872 Share on other sites More sharing options...
phpknight Posted October 21, 2007 Share Posted October 21, 2007 Okay, I see. If that is the case, the code we would need to see is probably above that. I would say to spit out the query as text for each one so you can see what you are doing. You are probably not changing the $savefile variable correctly, and it is asking for the same file twice. If so, then the code is simply doing what you are asking it to do, but the logic is wrong. You can also try running them through phpMyAdmin to get a better handle on what is happening. If that does not work, make sure to dump the $_FILES array and to make sure the upload is what you expect. It could be a form error, but I would try the php stuff first. There is also the mysql_insert_id function. If you are not using that, it might help as well, assuming that the id column is a primary key auto_increment field. Let me know what you find. Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-374906 Share on other sites More sharing options...
The Little Guy Posted October 21, 2007 Author Share Posted October 21, 2007 OK... Here is the entire page: <?php include"db.php"; session_start(); $a = 1; $twoUp = FALSE; foreach ($_FILES["file"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["file"]["tmp_name"][$key]; $name = $_FILES["file"]["name"][$key]; $file = getext($name); $time = time(); $string = "abcdefghijklmnopqrstuvwxyz0123456789"; $randnum = ''; for($i=0;$i<25;$i++){ $pos = rand(0,36); $randnum .= $string{$pos}; } $dircnt=0; $dirarr = array(); foreach(ListDescendantDirectories('guest_images') as $dir){ if(preg_match("~/thumbs~",$dir)){ continue; }else{ array_push($dirarr,$dir); $dircnt++; } } $filee = array_rand($dirarr); $savelocation = $dirarr[$filee]; #1 equals overwrite $guestTypes = array(".jpg",".gif",".png"); if(in_array($file,$guestTypes)){ move_uploaded_file($tmp_name, $savelocation."/".$time.$randnum.$name); createThumbnail($savelocation, $time.$randnum.$name, $savelocation.'/thumbs', 120, 80); $_SESSION['guestfile'.$a] = "http://tzfiles.com/$savelocation/".$time.$randnum.$name; $_SESSION['guestfile'.$a.'error'] = 1; $saveFile = $time . $randnum . $name; mysql_query("INSERT INTO guest_images (`directory`,`file`) VALUES ('$savelocation','$saveFile')"); $sql = mysql_query("SELECT id FROM guest_images WHERE `directory`='$savelocation' AND `file`='$saveFile' LIMIT 1"); $row = mysql_fetch_array($sql); if($twoUp){ $imID2 = '&imageID2='.$row['id']; }else{ $imID2 = ''; } if(!$twoUP){ $imID1 = '?imageID='.$row['id']; if(empty($_FILES['file']['name'][1])){ $twoUp = FALSE; break; }else{ $twoUp = TRUE; } } }else{ $_SESSION['guestfile'.$a.'error'] = 2; if(!in_array($file,$guestTypes)){ $_SESSION['guestfile'.$a.'error_txt'] .= '<span style="color:red">Incorrect File Type .jpg, .gif, .png only</span>'; } } } $a++; } header("Location: guestImage.php".$imID1.$imID2); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-375055 Share on other sites More sharing options...
phpknight Posted October 21, 2007 Share Posted October 21, 2007 For each loop, print $name and see if they are the same or different. Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-375087 Share on other sites More sharing options...
The Little Guy Posted October 21, 2007 Author Share Posted October 21, 2007 They are different. Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-375107 Share on other sites More sharing options...
phpknight Posted October 22, 2007 Share Posted October 22, 2007 What about the queries? Are they the same? And also, do a row count to see how many rows are being returned. Quote Link to comment https://forums.phpfreaks.com/topic/74158-truefalse-or-mysql-issue/#findComment-375154 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.