Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.