Forum Moderators: coopster

Message Too Old, No Replies

anyone know why the loop doesnt work please

         

Smad

10:25 am on Jan 16, 2004 (gmt 0)

10+ Year Member



heres the code.

loop works on its own but with the insert sql code its ignored?.

$sql = "insert into brokerage (type, price, make, model, year, engine_type, engine_hrs, fuel, LOA, beam, accommodation, brief, description, finance, warranty, date, maxspeed, lying) values ('$type', '$price', '$make', '$model', '$year', '$engine_type', '$engine_hrs', '$fuel', '$LOA', '$beam', '$accommodation', '$brief', '$description', '$finance', '$warranty', '$date', '$maxspeed', '$lying')";
$result = mysql_query($sql, $conn);
$boatID = mysql_insert_id();

// image uploader
$uploaddir = 'uploads/';
$tot = count($userfile);
$num = 0;
print "test";

for($q=0;$q<$tot;$q++){

$picture[$q] = $_FILES['userfile']['tmp_name'][$q];

if ($_FILES['userfile']['name'][$q] == "") continue;
print "test";
$picturename[$q] = "".uniqid(I).".jpg";
move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $picturename[$q]);
$filepath = 'uploads/' .$picturename[$q];
$sqlimage = "update brokerage
set picture".$num." = '$filepath'
where id = $boatID";
$resultimage = mysql_query($sqlimage, $conn);
if (!$resultimage) {
print "There was a database error when executing <pre>$sqlimage</pre>";
print mysql_error();
exit;
$num = $num + 1;
}
}

[edited by: jatar_k at 4:37 pm (utc) on Jan. 16, 2004]
[edit reason] fixed sidescroll [/edit]

jatar_k

4:39 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what happens specifically? errors? nothing?

Smad

6:04 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



nothing the first sql is performed and DB updated but everything after the FOR loop is ignored.. it works alone which i cant understand...no errors nothing.

jamesa

6:30 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's the value of $tot right before entering the for loop?

justageek

7:26 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may also be getting db errors but not seeing it. Echo out your statement to ensure it is correct and also echo out any mysql errors after the update to see if that is causing anything.

JAG

Smad

7:47 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



hmm it seems $tot is 0 when it should be 6 based on the 6 fields on the input form. I will review the form layout.

Smad

7:50 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



damn, it turned out to be the form.. do i feel stupid..

thanks for looking into this tho all..

jatar_k

7:56 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



don't worry, we all do it.

Sometimes you just need an extra pair of eyes. :)