Jump to content

spenceddd

Members
  • Posts

    107
  • Joined

  • Last visited

    Never

Everything posted by spenceddd

  1. Hi, My form is trying to add an item to the database when a button is clicked using this extract from my code: $query="INSERT INTO Portfolio.skillsList ('ID','NAME') VALUES (NULL ,'$_POST[skillField]')"; The error is as follows: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ID','NAME') VALUES (NULL ,'IOIOI')' at line 1 Does anyone have any ideas as to what is wrong with the syntax? Thanks a lot. Spencer
  2. Thanks rajivgonsalves but the text field stills seems to show only a numeric value....
  3. Hi, This is just a quickie, at the moment I can get a numeric value driven by the dropdown selection into a text box using this code in the drop down: <select name="skillsListDropDown" onchange="document.skillsForm.skillField.value=this.choice"> and this code for the text field: <input name="skillField" type="text" size="25"> ...but what I actually want is to get the text from the selected drop down item. You can see the form here: http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php it is the Manage Skills List section. Thanks in advance. Spencer
  4. Hi I keep getting this error when trying to update a row in my database: Unknown column 'xxx' in 'field list' the line of code which must be responsible for this is: $query="UPDATE PortfolioItems SET PortfolioItems.name=$name WHERE id=$id"; ...even though there is a colomn called name in my database. Can anyone help? Thanks Spencer
  5. Yes of course, here is the file list: weekScan.jpg 1Autumn Leaves.jpg Creekbo.jpg Croak.jpg Desert Landscape.jpg Dock.jpg Fluence-1600x1200.jpg Garden.jpg Green Sea Turtle.jpg IMG_0754.JPG Tree.jpg of which only the item: 1Autumn Leaves.jpg odesn't load into the drop down list. Also if i change the names of the other items to inlcude numbers at the start of the name, they stop working too. You can see the form here where the image box drop downs are the drop downs in question. http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php Hopefully that helps a bit. Spencer
  6. Hi, I am very new to php and am struggling to work out how to delete a portfolio item (a row from my database using my form which is here): http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php The problem comes I think because I already have one submit button on the page as you can see. Ideally when pressed the delete button will remove the row from the database with the same name that is showing in the top drop down box and either go to a page with a 'delete successfull' message or the message wil appear next to the button. Here is the code for the page: <?php include('connectToDB.php'); include('populateDropDownList.php'); include('buildFileList5.php'); //include('deleteCurrentItem.php'); ?> <html> <head> <script type="text/javascript"> var existingPortfolioItems = new Array(); function chkFrm(el){ if(el.selectedIndex == 0){ alert("Please choose an option"); return false } else{ el.form.submit(); } } function hello(){ //alert("Hello It works"); var result = "boo"; location.replace(\"deleteCurrentItem.php?result\"+ result); //location.href = "deleteCurrentItem.php?Result=" + Result; } function updateImg(ele, img) { // using arguments makes this function reusable for multiple items // ele = dropdown object // img = image object document.getElementById(img).src = "uploaded/thumbs/" + ele.value; //document[img].alt = ele.value; } </script> </head> <body> <h1>Select Existing Item: </h1> <form action"deleteCurrentItem.php" method="POST" >Existing Item: <select name="name" onChange="chkFrm(this)"> <option value="Choose" <?php if (!(strcmp("Choose", $_POST['name']))) {echo "SELECTED";} ?>>Choose Portfolio Items</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> ------------> <input type="button" name="deleteButton" onClick="hello();" value="Delete Current Item"> </form> <form action="addToPortfolioItems.php" onSubmit="return checkForDuplicateNames("name")" method="post"> <table width="884" height="789" border="1"> <tr> <td width="417" rowspan="5" valign="top">Name: <input name="name" type="text" value="<?php echo $row_chosen_pItem['name']; ?>" size="25"> <p>Short Description:</p> <p> <textarea name="shortDesc" cols="55" rows="4"><?php echo $row_chosen_pItem['shortDesc']; ?></textarea> </p> <p>Long Description:</p> <p> <textarea name="longDesc" cols="55" rows="10"><?php echo $row_chosen_pItem['longDesc']; ?></textarea> </p> <p>Related Item01 <select name="relatedItem01" > <option value="" >Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $row_chosen_pItem['relatedItem01']))) {echo "SELECTED";}?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?></select> </p> <p>Related Item02 <select name="relatedItem02" > <option value="" >Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $row_chosen_pItem['relatedItem02']))) {echo "SELECTED";}?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?></select> </p> <p>Related Item03 <select name="relatedItem03" > <option value="" >Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $row_chosen_pItem['relatedItem03']))) {echo "SELECTED";}?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?></select> </p> <p>Keywords: <input name="keywords" type="text" value="<?php echo $row_chosen_pItem['keywords']; ?>" size="50"> <p>Skills: <input name="skills" type="text" value="<?php echo $row_chosen_pItem['skills']; ?>" size="50"> <p> <input type="submit"/> </td> <td width="451" height="157" align="left"><p>Image01: <select name="img01" onChange="updateImg(this, 'thumbImg01')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img01']); ?> </select></p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img01'];?>" alt="hoho" name="thumbImg01" width="100" height="100" id="thumbImg01"></td> </tr> </table></td> </tr> <tr> <td height="150" align="left"><p>Image02: <select name="img02" onChange="updateImg(this, 'thumbImg02')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img02']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg02" width="100" height="100" id="thumbImg02"></td> </tr> </table></td> </tr> <tr> <td height="157" align="left"><p>Image03: <select name="img03" onChange="updateImg(this, 'thumbImg03')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img03']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img03'];?>" alt="hh" name="thumbImg03" width="100" height="100" id="thumbImg03"></td> </tr> </table></td> </tr> <tr> <td width="451" height="109" align="left"><p>Image04: <select name="img04" onChange="updateImg(this, 'thumbImg04')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img04']); ?> </select> </p> <img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg04" width="100" height="100" id="thumbImg04"></td> </tr> <tr> <td align="left"><p>Image05: <select name="img05" onChange="updateImg(this, 'thumbImg05')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img05']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img05'];?>" alt="hh" name="thumbImg05" width="100" height="100" id="thumbImg05"></td> </tr> </table></td> </tr> </table> <p> </p> </form> <h1>Upload an image file</h1> <form enctype="multipart/form-data" action="uploader.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > </form> <h1>Upload a movie file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> <h1>Upload a download file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> </body> </html> <?php ?> Thanks in advance for any help on this. Spencer
  7. This file returns a list of filenames to help populate a drop down in my form. For some reason it ignores any file names that begin with numbers, could anyone please tell my why and show me how to solve it? <?php function buildFileList5($theFolder, $value) { // Execute code if the folder can be opened, or fail silently if ($contents = @ scandir($theFolder)) { // initialize an array for matching files $found = $output = array(); // Create an array of file types $fileTypes = array('jpg','jpeg','gif','png','JPG'); // Traverse the folder, and add filename to $found array if type matches $found = array(); foreach ($contents as $item) { $fileInfo = pathinfo($item); if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'],$fileTypes)) { $found[] = $item; } } // Check the $found array is not empty if (!empty($found)) { // Sort in natural, case-insensitive order, and populate menu natcasesort($found); //$selectedImage = ""; //default image foreach ($found as $filename){ $sel = ""; //reset $sel $selectedImage = ""; //default image if($value == $filename) { $sel = "selected=\"selected\""; $selectedImage = $filename; } $output[] = "<option value=\"$filename\" $sel>$filename</option>\n"; } } return (empty($output) ? '<option value="-1">No Items Found in `'.$theFolder.'`</option>' : '<option value="-1">Please select an Item</option'."\n".join("\n",$output)); } } ?> Thanks a million for any help on this. Spencer
  8. Ah yes well I didn't show all the code as I thought it may raise more questions but that code does seem to work, or at least the drop dowm functions correctly. I'm just trying to understand it so I can apply it to other drop downs in my form. Here is the rest of the code for the drop down: <select name="name" onChange="chkFrm(this)"> <option value="Choose" <?php if (!(strcmp("Choose", $_POST['name']))) {echo "SELECTED";} ?>>Choose Portfolio Items</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> Again any help on explaining this would help me a lot. Spence
  9. Hi, Being an absolute novice I am struggling to work out how this if statement work (within some code for a drop down menu): <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option> What I don't understand is why the string compare function is comparing two things that will never match, $row_PortfolioItems['id'] and $_POST['name'] as one is a number and one is a string...also I don't really get how the whole line works in terms of the html that it generates. Would be grateful if someone could break it down for me. Thanks for any help. Spencer
  10. Got it working now, great news. Thanks for your help again. Im now attempting to re-apply some more code, could anyone explain how this line works please?: <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option> I get the basic gist but the if function is baffling me, is it using shorthand code? Thanks Spencer
  11. Yes it all seems to be working now apart from the default value in the drop down, I think it might be always showing the final file name in the list. Ill try and figure out why.
  12. Ah, i have just noticed that if i create a new item (form submission to database) from scratch it seems to work ok apart from the fact it keeps loading the Winter Leaves title as the default drop down item. I'm going to remove Winter leaves from my webspace and see if it helps.
  13. Ok I have just done that. There appears to be values there but for some reason it is changing them all to Winter leaves and still not displaying them....strange
  14. Yes and i double checked that too, here is the code from the file: <?php include('connectToDB.php'); include('populateDropDownList.php'); include('buildFileList5.php'); ?> <html> <head> <script type="text/javascript"> var existingPortfolioItems = new Array(); function chkFrm(el){ if(el.selectedIndex == 0){ alert("Please choose an option"); return false } else{ el.form.submit(); } } function updateImg(ele, img) { // using arguments makes this function reusable for multiple items // ele = dropdown object // img = image object document.getElementById(img).src = "uploaded/thumbs/" + ele.value; //document[img].alt = ele.value; } function checkForDuplicateNames(nameToCheck) { Array.prototype.chkforDuplicates = function (value) // Returns true if the passed value is found in the // array. Returns false if it is not. { var i; var ctr = 0; for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return true; } } return false; }; } </script> </head> <body> <h1>Select Existing Item: </h1> <form action"" method="POST" >Existing Item: <select name="name" onChange="chkFrm(this)"> <option value="Choose" <?php if (!(strcmp("Choose", $_POST['name']))) {echo "SELECTED";} ?>>Choose Portfolio Items</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> </form> <form action="addToPortfolioItems.php" onSubmit="return checkForDuplicateNames("name")" method="post"> <table width="979" height="481" border="1"> <tr> <td width="417" rowspan="3">Name: <input name="name" type="text" value="<?php echo $row_chosen_pItem['name']; ?>" size="25"> <p>Short Description:</p> <p> <textarea name="shortDesc" cols="55" rows="4"><?php echo $row_chosen_pItem['shortDesc']; ?></textarea> </p> <p>Long Description:</p> <p> <textarea name="longDesc" cols="55" rows="10"><?php echo $row_chosen_pItem['longDesc']; ?></textarea> </p> <p> </p></td> <td width="257"><p>Image01: <select name="img01" onChange="updateImg(this, 'thumbImg01')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img01']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img01'];?>" alt="hoho" name="thumbImg01" width="100" height="100" id="thumbImg01"></td> <td><?php echo $row_chosen_pItem['img01']; ?> </td> </tr> </table></td> <td width="283" height="109"><p>Image04: <select name="img04" onChange="updateImg(this, 'thumbImg04')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img04']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg04" width="100" height="100" id="thumbImg04"></td> <td> </td> </tr> </table></td> </tr> <tr> <td height="150"><p>Image02: <select name="img02" onChange="updateImg(this, 'thumbImg02')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img02']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg02" width="100" height="100" id="thumbImg02"></td> <td> </td> </tr> </table></td> <td><p>Image05: <select name="img05" onChange="updateImg(this, 'thumbImg05')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img05']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img05'];?>" alt="hh" name="thumbImg05" width="100" height="100" id="thumbImg05"></td> <td> </td> </tr> </table></td> </tr> <tr> <td height="157"><p>Image03: <select name="img03" onChange="updateImg(this, 'thumbImg03')"> <?php echo buildFileList5('uploaded',$row_chosen_pItem['img03']); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img03'];?>" alt="hh" name="thumbImg03" width="100" height="100" id="thumbImg03"></td> <td> </td> </tr> </table></td> <td> </td> </tr> </table> <p>Related Item01 <select name="relatedItem01" > <option value="" <?php if (!(strcmp("Choose", $_POST['relateItem01']))) {echo "SELECTED";} ?>>Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['relateItem01']))) {echo "name";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> </p> <p>Related Item02 <select name="relateItem02" > <option value="Choose" <?php if (!(strcmp("Choose", $_POST['relateItem01']))) {echo "SELECTED";} ?>>Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['relateItem02']))) {echo "name";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> <p>Related Item03 <select name="relateItem03" > <option value="Choose" <?php if (!(strcmp("Choose", $_POST['relateItem03']))) {echo "SELECTED";} ?>>Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['relateItem01']))) {echo "name";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> <p>Keywords: <input name="keywords" type="text" value="<?php echo $row_chosen_pItem['keywords']; ?>" size="50"> <p>Skills: <input name="skills" type="text" value="<?php echo $row_chosen_pItem['skills']; ?>" size="50"> <p><input type="submit"/> </form> <h1>Upload an image file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> <h1>Upload a movie file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> <h1>Upload a download file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> </body> </html> <?php ?>
  15. Hi Buddski, Thanks so much for your help I have tried to get that working but have a couple of issues: All the dropdown that have an image assigned to them always seem to show the same image name each time, 'Winter Leaves' Only the first image box seems to show an image - this may be my fault but I haven't been able to get to the bottom of it yet... Spencer
  16. Thanks guys! I will try to implement your suggestions. I might take a while but I will let you know how it goes. Spencer
  17. yeah sure! I will insert all the files here (except the conection info of course). This is the file called simpleForm.php: <?php include('connectToDB.php'); include('populateDropDownList.php'); include('buildFileList5.php'); ?> <html> <head> <script type="text/javascript"> var existingPortfolioItems = new Array(); function chkFrm(el){ if(el.selectedIndex == 0){ alert("Please choose an option"); return false } else{ el.form.submit(); } } function updateImg(ele, img) { // using arguments makes this function reusable for multiple items // ele = dropdown object // img = image object document.getElementById(img).src = "uploaded/thumbs/" + ele.value; //document[img].alt = ele.value; } function checkForDuplicateNames(nameToCheck) { Array.prototype.chkforDuplicates = function (value) // Returns true if the passed value is found in the // array. Returns false if it is not. { var i; var ctr = 0; for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return true; } } return false; }; } </script> </head> <body> <h1>Select Existing Item: </h1> <form action"" method="POST" >Existing Item: <select name="name" onChange="chkFrm(this)"> <option value="Choose" <?php if (!(strcmp("Choose", $_POST['name']))) {echo "SELECTED";} ?>>Choose Portfolio Items</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['name']))) {echo "SELECTED";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> </form> <form action="addToPortfolioItems.php" onSubmit="return checkForDuplicateNames("name")" method="post"> <table width="979" height="481" border="1"> <tr> <td width="417" rowspan="3">Name: <input name="name" type="text" value="<?php echo $row_chosen_pItem['name']; ?>" size="25"> <p>Short Description:</p> <p> <textarea name="shortDesc" cols="55" rows="4"><?php echo $row_chosen_pItem['shortDesc']; ?></textarea> </p> <p>Long Description:</p> <p> <textarea name="longDesc" cols="55" rows="10"><?php echo $row_chosen_pItem['longDesc']; ?></textarea> </p> <p> </p></td> <td width="257"><p>Image01: <select name="img01" onChange="updateImg(this, 'thumbImg01')"> <option value=-"-1" ><?php echo $row_chosen_pItem['img01']; ?></option> <?php buildFileList5('uploaded');?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img01'];?>" alt="hoho" name="thumbImg01" width="100" height="100" id="thumbImg01"></td> <td><?php echo $row_chosen_pItem['img01']; ?> </td> </tr> </table></td> <td width="283" height="109"><p>Image04: <select name="img04" onChange="updateImg(this, 'thumbImg04')"> <option value=-"-1" ><?php echo $row_chosen_pItem['img02']; ?> </option> <?php buildFileList5('uploaded'); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg04" width="100" height="100" id="thumbImg04"></td> <td> </td> </tr> </table></td> </tr> <tr> <td height="150"><p>Image02: <select name="img02" onChange="updateImg(this, 'thumbImg02')"> <option value=-"-1" ><?php echo $row_chosen_pItem['img02']; ?> </option> <?php buildFileList5('uploaded'); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img04'];?>" alt="hh" name="thumbImg02" width="100" height="100" id="thumbImg02"></td> <td> </td> </tr> </table></td> <td><p>Image05: <select name="img05" onChange="updateImg(this, 'thumbImg05')"> <option value=-"-1" >Choose Image </option> <?php buildFileList5('uploaded'); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img05'];?>" alt="hh" name="thumbImg05" width="100" height="100" id="thumbImg05"></td> <td> </td> </tr> </table></td> </tr> <tr> <td height="157"><p>Image03: <select name="img03" onChange="updateImg(this, 'thumbImg03')"> <option value=-"-1" ><?php echo $row_chosen_pItem['img03']; ?> </option> <?php buildFileList5('uploaded'); ?> </select> </p> <table width="24" border="1"> <tr> <td><img src="uploaded/thumbs/<?php echo $row_chosen_pItem['img03'];?>" alt="hh" name="thumbImg03" width="100" height="100" id="thumbImg03"></td> <td> </td> </tr> </table></td> <td> </td> </tr> </table> <p>Related Item01 <select name="relatedItem01" > <option value="" <?php if (!(strcmp("Choose", $_POST['relateItem01']))) {echo "SELECTED";} ?>>Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['relateItem01']))) {echo "name";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> </p> <p>Related Item02 <select name="relateItem02" > <option value="Choose" <?php if (!(strcmp("Choose", $_POST['relateItem01']))) {echo "SELECTED";} ?>>Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['relateItem02']))) {echo "name";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> <p>Related Item03 <select name="relateItem03" > <option value="Choose" <?php if (!(strcmp("Choose", $_POST['relateItem03']))) {echo "SELECTED";} ?>>Choose Item</option> <?php do { ?> <option value="<?php echo $row_PortfolioItems['id']?>"<?php if (!(strcmp($row_PortfolioItems['id'], $_POST['relateItem01']))) {echo "name";} ?>><?php echo $row_PortfolioItems['name']?></option> <?php } while ($row_PortfolioItems = mysql_fetch_assoc($PortfolioItems)); $rows = mysql_num_rows($PortfolioItems); if($rows > 0) { mysql_data_seek($PortfolioItems, 0); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); } ?> </select> <p>Keywords: <input name="keywords" type="text" value="<?php echo $row_chosen_pItem['keywords']; ?>" size="50"> <p>Skills: <input name="skills" type="text" value="<?php echo $row_chosen_pItem['skills']; ?>" size="50"> <p><input type="submit"/> </form> <h1>Upload an image file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> <h1>Upload a movie file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> <h1>Upload a download file</h1> <form enctype="multipart/form-data" action="uploaderAndResize.php" method="POST"><input type="file" name="myfile"> <p> <input name="Submit" type='submit' value="upload" > <?echo $heldVariable?> </form> </body> </html> <?php ?> This is the file called populateDropDownList.php: <?php /* 1. Query the database and get the ID and name FROM the table PortfolioItems */ mysql_select_db($database_db, $dbc); $query_PortfolioItems = "SELECT id, name FROM PortfolioItems"; $PortfolioItems = mysql_query($query_PortfolioItems, $dbc) or die(mysql_error()); $row_PortfolioItems = mysql_fetch_assoc($PortfolioItems); $totalRows_PortfolioItems = mysql_num_rows($PortfolioItems); /* 2. If the form was submitted then get the ID from the name text box * This is used for the form location */ $colname_chosen_pItem = "-1"; if (isset($_POST['name'])) { $colname_chosen_pItem = (get_magic_quotes_gpc()) ? $_POST['name'] : addslashes($_POST['name']); } mysql_select_db($database_db, $dbc); $query_chosen_pItem = sprintf("SELECT * FROM PortfolioItems WHERE id = %s", $colname_chosen_pItem); $chosen_pItem = mysql_query($query_chosen_pItem, $dbc) or die(mysql_error()); $row_chosen_pItem = mysql_fetch_assoc($chosen_pItem); $totalRows_chosen_pItem = mysql_num_rows($chosen_pItem); ?> This is the file called addToPortfolioItems.php: <?php include('connectToDB.php'); ?> <html> <head> <form action="" method="POST"> <input name="name" type="text" value="<?php echo $_POST[name]; ?>" size="25"> <?php $nameField= $_POST[name]; //testForDuplicateNames $query="SELECT * FROM PortfolioItems WHERE name='$_POST[name]'"; $result=mysql_query($query); $num=mysql_num_rows($result); if ($num == 0){ $query="INSERT INTO PortfolioItems (name, shortDesc, longDesc, keywords, skills, img01, img02, img03, img04, img05) VALUES ('$_POST[name]','$_POST[shortDesc]','$_POST[longDesc]', '$_POST[keywords]', '$_POST[skills]', '$_POST[img01]', '$_POST[img02]', '$_POST[img03]', '$_POST[img04]', '$_POST[img05]')"; $result=mysql_query($query); header("Location: simpleForm.php"); //* } else{ echo ("<script> <!-- location.replace(\"InvalidName.html\"); --> </script>"); } //*/ ?> </form> </head> </html> and finally here is the buildFileList5.php again: <?php function buildFileList5($theFolder) { // Execute code if the folder can be opened, or fail silently if ($contents = @ scandir($theFolder)) { // initialize an array for matching files $found = array(); // Create an array of file types $fileTypes = array('jpg','jpeg','gif','png'); // Traverse the folder, and add filename to $found array if type matches $found = array(); foreach ($contents as $item) { $fileInfo = pathinfo($item); if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'],$fileTypes)) { $found[] = $item; } } // Check the $found array is not empty if ($found) { // Sort in natural, case-insensitive order, and populate menu natcasesort($found); $selectedImage = ""; //default image foreach ($found as $filename) { if(!empty($_POST['img01']) && $_POST['img01'] == $filename) { $sel = "SELECTED"; $selectedImage = $filename; } echo "<option value='$filename' $sel>$filename</option>\n"; } } } } ?> Thanks a lot Buddski and sorry if some of the code is a bit messed up, like I said I'm very new to this stuff. Spencer
  18. Hello, Please bear with me as I am very new to php and html. I have a form with several drop down menus, the one at the top shows a list that when an item is selected fills in the form below including the other drop downs. So when an item is selected the form gets info from a mysql database and then fills in the form. At this point the user can further modify the form and re-submit it to update the database. This means that the drop downs in the form not only need to display the relavent options from the database to reflect the existing choice but also when clicked on show a list to allow the user the change the selection from the list. This means that the dropdown needs to: show the words 'select item' when the form is first loaded and the form is empty show the current selection when the defined by a selection in the top drodown show all the available items when the list is dropped down Curently my drop down does only this: shows the nothing when the form is first loaded and the form is empty shows the current selection when defined by a selection in the top drodown show all the available items when the list is dropped down plus the one that was there before it was clicked on, therefore doubing the option up showing the same option twice The form is here if you would like to see it in action: http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php And a snippet of code from one of th drop downs is here: <select name="img01" onChange="updateImg(this, 'thumbImg01')"> <option value=-"-1" ><?php echo $row_chosen_pItem['img01']; ?></option> <?php buildFileList5('uploaded');?> </select> the code inside the 'buildFileList5' looks like this: <?php function buildFileList5($theFolder) { // Execute code if the folder can be opened, or fail silently if ($contents = @ scandir($theFolder)) { // initialize an array for matching files $found = array(); // Create an array of file types $fileTypes = array('jpg','jpeg','gif','png'); // Traverse the folder, and add filename to $found array if type matches $found = array(); foreach ($contents as $item) { $fileInfo = pathinfo($item); if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'],$fileTypes)) { $found[] = $item; } } // Check the $found array is not empty if ($found) { // Sort in natural, case-insensitive order, and populate menu natcasesort($found); $selectedImage = ""; //default image foreach ($found as $filename) { if(!empty($_POST['img01']) && $_POST['img01'] == $filename) { $sel = "SELECTED"; $selectedImage = $filename; } echo "<option value='$filename' $sel>$filename</option>\n"; } } } } ?> I hope that is enough info to explain it. If anyone could tell how to get the dropdown working properly I would be very gratefull. Thanks a lot. Spencer
  19. Hi I have just tried that and now if it errors on the buildfileList5.php file on the line where it says: $sel = "SELECTED":""; It says unexpencted ":" I'm not sure how that operator works so cannot fix it on my own, any ideas? Spence
  20. Ok will do and thanks a million for your help, you are very kind.
×
×
  • 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.