Jump to content

Gokul

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Gokul's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry, I was hasty in not figuring it out myself. Got it now and this is the code <?php echo '<form action="" method="POST">'; for($i=1;$i<=5;$i++) { echo "<input type=\"checkbox\" name=\"box[$i]\" value=\"$i\" />\r Notes <input type=\"textbox\" name=\"note[$i]\" size=\"50\" /><hr />\r"; } echo "<input type=\"Submit\" name=\"submit\" value=\"Submit\" />\r </form>"; $box = $_POST['box']; $note = $_POST['note']; $total = count($box); if(isset($_POST['submit']) && is_array($box)) { foreach ($box as $checked) { echo "Value $checked: $note[$checked]<br>"; } } ?> Many thanks.....
  2. Hello again. I forgot to mention that I need to get the value of the checkbox with reference to the text box. This is because is need to update the database where the ID equals the value of the checkbox.
  3. Hi Wolhpie. Ahh that's brilliant. So you're saying to check and see if the checkbox is an array and if it is then execute the rest of the code. Many thanks to both for your help as I was stuck for ages.
  4. Hi Teamatomic. Many thanks for your reply and yes it nearly solves the problem however, a warning message appears when the submit button is pressed and no checkboxes are checked. I don't think there is anyway to suppress warning messages for the foreach loop according to the PHP.net manual.
  5. Hello all php people. Many apologies if this has been asked before (which it most probably has) but I've been struggling with this for a while now and would greatly appreciate any help. Tried searching google and forums but cannot seem to find much info, and what I have found didn't make much sense to me. For this example, I have created a simple form with checkboxes and text boxes show below: - <?php echo "<form action=\"$_SERVER[php_SELF]\" method=\"POST\">\r"; for($i=0;$i<=5;$i++) { echo "<input type=\"checkbox\" name=\"checked[]\" value=\"$i\" />\r Notes <input type=\"textbox\" name=\"notes[]\" size=\"50\" /><hr />\r"; } echo "<input type=\"Submit\" name=\"submit\" value=\"Submit\" />\r </form>"; $checked = $_POST['checked']; $total = count($checked); if(isset($_POST['submit'])) { for($j=0;$j<=$total;$j++) { echo "$checked[$j] – ".$_POST['notes'][$j]."<br />"; } } ?> I just want to simply loop through the form and get the value of the text box only when its checkbox is checked. The for loop I have written is me trying to experiment with retrieving the checkbox value along with its relevant text box value but am not having much luck. Thanks in advance for this.
  6. Nobody wants to help me...... come on please
  7. Hi. I am a newbie at php an have been scratching my head to work out how to reduce the file size of multiple image uploads through an HTML form. The following HTML form looks like this: - <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><p><strong>Multiple Files Upload</strong></p></td> </tr> <tr> <td>Company <input type="text" name="company" id="company" size="50"> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td>Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> My PHP script so far is successfully creating a new directory, saving images in to that new directory and outputting the results to the user in their browsers for every image which has finished uploading. I have tried some code from this site and others to reduce the file size of each image uploaded but have had no luck to get it to work. My script named "multiple_upload_ac.php" is as follows: - <?php //get company name from html form $dirName = $_POST["company"]; //make directory of the company name mkdir($dirName, 0777); //for each image uploaded, move image from temp directory to created company name directory foreach ($_FILES["ufile"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["ufile"]["tmp_name"][$key];//temporary image uploaded $name = $_FILES["ufile"]["name"][$key];//prefix file name with "small" //$smallPic = imagejpeg($name, null, 25) $path = move_uploaded_file($tmp_name, "$dirName/$name");//move temporary file to named directory. Temporary image automatically destroyed //for each file, show successful upload, file size and show thumbnail of image echo "File $name successfully uploaded"."<br>"; echo "Size of file is ". filesize("$dirName/$name"). " bytes". "<br>"; echo "<img src=\"$dirName/$name\" width=\"150\" height=\"150\">". "<br><br>"; } } ?> I apologise if this thread has been posted before and appreciate any help, links to tutorials or any other sites that can help me develop my skills further. Thanking everyone in advance.
×
×
  • 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.