jpratt Posted September 15, 2007 Share Posted September 15, 2007 I have a form with html: <?php echo "<form id='form1' enctype='multipart/form-data' name='form1' method='post' action='attach2.php'>"; $sql = "SELECT * FROM attachments"; $prepstatement = $db->prepare($sql); $prepstatement->execute(); while($row = $prepstatement->fetch()) { echo "<tr style='font-size:11px;'>\n"; echo "<td><input type='checkbox' name='idnum[]' value='" . $row['attachID'] . "' />\n"; echo "<td>" . $row['attachname'] . "</td>\n"; echo "<td colspan='2'>" . $row['description'] . "</td>\n"; echo "<td><a style='color:#000099; text-decoration:underline;' href='attachments/" . $row['location'] . "'>" . $row['location'] . "</a></td></tr>\n"; } unset($sql, $prepstatement); ?> <tr height="25"><td></td></tr> <tr> <td colspan="2"><strong><font size="2">Name:</font></strong></td> <td colspan="3"><?php echo "<input name='name' type='text' />"; ?> </td> </tr> <tr> <td colspan="2"><strong><font size="2">File:</font></strong></td> <td colspan="3"> <?php echo "<input name='userfile' type='file' />"; ?> </td> </tr> <tr> <tr> <td colspan="2"><strong><font size="2">Description:</font></strong></td> <td colspan="3"> <?php echo "<textarea name='description' cols='35' rows='4'></textarea>"; ?> </td> </tr> <tr> <td colspan="2"><div align="right"> <?php echo "<input style='background-color:#C8DAE8;' type='submit' name='1' id='button' value='Add' />"; ?> </div></td> <td colspan="3"><?php echo "<input type='submit' name='2' id='button5' value='Remove' />"; ?></td> </tr><?php echo "</form>"; ?> and on the attach2.php file looks like this: <?php require_once('db/config.php'); if ($_POST['1'] == 'Add') { //ghfgh $name = $_POST['name']; $description = $_POST['description']; $currentdir = $_SERVER["DOCUMENT_ROOT"]."/"; $currentdir = str_replace ("/", "\\", $currentdir); $currentdir = str_replace ("www\\localhost\\", "", $currentdir); $uploadtempdir = $currentdir . "temp/"; ini_set('upload_tmp_dir', $uploadtempdir); $uploaddir = "attachments/"; $filename = $_FILES['userfile']['name']; $uploadfile = $uploaddir . $_FILES['userfile']['name']; move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); //dfghf $sql = "INSERT INTO attachments (attachname, location, description) VALUES ('$name', '$filename', '$description')"; $prepstatement = $db->prepare($sql); $prepstatement->execute(); } if ($_POST['2'] == 'Remove') { foreach($_POST['idnum'] as $remove) { $sql = "SELECT location FROM attachments WHERE attachID = '$remove'"; $prepstatement = $db->prepare($sql); $prepstatement->execute(); while($row = $prepstatement->fetch()) { $unlink = "attachments/" . $row['location']; unlink($unlink); } unset($sql, $prepstatement); $sql = "DELETE FROM attachments WHERE attachID = '$remove'"; $prepstatement = $db->prepare($sql); $prepstatement->execute(); } } header('Location:attach.php'); ?> The problem is it works on the first post, but after it goes back to attach.php and i hit add it think for a minute like it is doing the upload, then refreshes and does nothing. then if i upload again it works sometimes seems to be very random. I do not understand why it is so random in working. It nevers thows and error, just either works or not. Please help. Link to comment https://forums.phpfreaks.com/topic/69423-problem-with-form-value/ Share on other sites More sharing options...
jpratt Posted September 15, 2007 Author Share Posted September 15, 2007 any ideas? i got the value of $_POST['1'] and it was random either not set or was "Add". really weird. Link to comment https://forums.phpfreaks.com/topic/69423-problem-with-form-value/#findComment-348844 Share on other sites More sharing options...
jpratt Posted September 15, 2007 Author Share Posted September 15, 2007 ideas?? Link to comment https://forums.phpfreaks.com/topic/69423-problem-with-form-value/#findComment-349081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.