else statement not displaying data

Eonwe

New Member
i have some code to check for duplicates in a db before submitting the data, but the statement i have does not work. if a duplicate is found a message is returned to the form. however, it is not working and i am sure it has to do with my else statements near the bottom of the file being incorrect. assume all connections are working. where is the error? many thanks \[code\]<?php$array = split('[,]', $_POST['fileno']);if (isset($_POST['submit'])) { foreach ($array as $fileno) { if ($fileno == '' && $box == '') { echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must incude a box and a file' . '</div>'; } elseif ($fileno == '') { echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must enter a file reference' . '</div>'; } elseif ($box == '') { //echo error; echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must enter a box' . '</div>'; } else { $sql = "SELECT custref FROM files WHERE custref = '$fileno' "; $result = runSQL($sql) or die(mysql_error()); if (mysql_num_rows($result)>0){ echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . $fileno . ' is already in the database. No duplicates' . '</div>'; } $sql = "SELECT custref FROM boxes WHERE custref = '$box' "; $result = runSQL($sql) or die(mysql_error()); if (mysql_num_rows($result)>0){ echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . $box . ' is already in the database. No duplicates' . '</div>'; } else { //insert into db; echo '<div style="background-color:#ffa; padding:2px; color:#33CC33;font-size:12px;font-weight:normal">' . $fileno . "Box: " . $box . $authorised . 'Successfull' . '</div>'; $sql = "INSERT INTO `files` (customer, authorisation, boxstatus, boxref, custref, filestatus) VALUES ('$customer', '$authorised', '$boxstatus', '$box', '$fileno', $filestatus)"; $result = runSQL($sql) or die(mysql_error()); //echo 'This record is valid'; //header("Location: http://localhost/sample/admin/files/index.php"); //exit(); } } }}?>\[/code\]
 
Back
Top