Jump to content

fewkesy

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by fewkesy

  1. Just in case anyone else has a similar problem, I solved it by adding javascript to the onSubmit event of the form. By creating a javascript function that converts the raw html into the equivalent output when done through php using the following code. <script type="text/javascript"> function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } </script> This is then passed through with the other data in the form and can be reconverted back into the original raw code using the php function html_entity_decode().
  2. If you don't define the action attribute of the form tags, it simply defaults to the action being the current URL. The problem that I face lies within submitting the html code through the textarea tags.
  3. I'm trying to submit html/php code through an html form and then insert it into a mysql database. I've got the following code so far (without the insert into database query), however when I submit the form I get pushed through to my 403 page. If i comment out the textarea that contains the code I am trying to submit, then it goes through fine. Any ideas? <? if (isset($_POST['optone'])) {$optone=$_POST['optone']; $opttwo=$_POST['opttwo'];} if (isset($_POST['type'])) {if ($_POST['type']=='Theory') {$optone=1;} if ($_POST['type']=='Demo') {$optone=2;} $opttwo=$_POST['module'];} ?> <h3>Module administration</h3> <script> function setOptions(chosen) { var selbox = document.myform.opttwo; selbox.options.length = 0; if (chosen == " ") { selbox.options[selbox.options.length] = new Option('Please select an option first',' '); document.myform.go.disabled=true; } if (chosen == "1") { selbox.options[selbox.options.length] = new Option('Module 1','1'); selbox.options[selbox.options.length] = new Option('Module 2','2'); selbox.options[selbox.options.length] = new Option('Module 3','3'); selbox.options[selbox.options.length] = new Option('Module 4','4'); selbox.options[selbox.options.length] = new Option('Module 5','5'); selbox.options[selbox.options.length] = new Option('Module 6','6'); selbox.options[selbox.options.length] = new Option('Module 7','7'); selbox.options[selbox.options.length] = new Option('Module 8','8'); selbox.options[selbox.options.length] = new Option('Module 9','9'); selbox.options[selbox.options.length] = new Option('Module 10','10'); document.myform.go.disabled=false; } if (chosen == "2") { selbox.options[selbox.options.length] = new Option('Module 1','1'); selbox.options[selbox.options.length] = new Option('Module 2','2'); selbox.options[selbox.options.length] = new Option('Module 3','3'); selbox.options[selbox.options.length] = new Option('Module 4','4'); selbox.options[selbox.options.length] = new Option('Module 5','5'); selbox.options[selbox.options.length] = new Option('Module 6','6'); selbox.options[selbox.options.length] = new Option('Module 7','7'); selbox.options[selbox.options.length] = new Option('Module 8','8'); selbox.options[selbox.options.length] = new Option('Module 9','9'); selbox.options[selbox.options.length] = new Option('Module 10','10'); document.myform.go.disabled=false; } } </script> <br /> <center> <form name="myform" method='post'> Edit: <select id="optone" name="optone" size="1" onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);" > <option value=" " >--Choose--</option> <option value="1" >Theory</option> <option value="2" >Demo</option> </select> <select name="opttwo" size="1"> <option value=" " selected="selected">Please select an option first</option> </select> <input type='submit' name='go' id='go' value='Go' disabled='disabled'/> </form> </center> <br /><br /> <? if (isset($opttwo)) { if ($optone==1) {$query = "SELECT info,userscompleted,last_user,enabled FROM theorydata WHERE TheoryID=".$opttwo; $typestr='Theory'; $texthelp='Code must be entered in HTML';} if ($optone==2) {$query = "SELECT info,userscompleted,last_user,enabled FROM demodata WHERE DemoID=".$opttwo; $typestr='Demo'; $texthelp='Code must be entered in PHP';} $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $query2="SELECT full_name FROM users WHERE id=".$row['last_user']; $result2 = mysql_query($query2) or die(mysql_error()); $row2 = mysql_fetch_array($result2); ?> <form method='post' > <table> <tr> <td align='center'> Type: </td> <td> <input type='text' name='type' readonly='readonly' value="<? echo $typestr; ?>" /> </td> </tr> <tr> <td align='center'> Module: </td> <td> <input type='text' name='module' readonly='readonly' value="<? echo $opttwo; ?>" /> </td> </tr> <tr> <td align='center' > Enabled? </td> <td> <select name='enabled'> <option value='yes' <? if ($row['enabled'] == '1') {echo "selected='selected'";}?> >Yes</option> <option value='no' <? if ($row['enabled'] == '0') {echo "selected='selected'";}?> >No</option> </select> </td> </tr> <tr> <td align='center'> Code: </td> <td> <center><font color='red'><? echo $texthelp; ?></font></center> <textarea name='info' rows=35 cols=80><? echo htmlentities($row['info']); ?></textarea> </td> </tr> <tr> <td align='center' > Users completed: </td> <td> <input type='text' name='userscompleted' value="<? echo $row['userscompleted']; ?>" size=4/> </td> </tr> <tr> <td align='center' > Last user: </td> <td> <input type='text' name='last_user' readonly='readonly' value="<? echo $row2['full_name']; ?>" /> </td> </tr> <tr> <td></td> <td align='center'> <input type='submit' value='Edit'/> </td> </tr> </table> </form> <? }//close isset(opttwo) ?>
  4. Thanks, can't believe it was that simple. Just in case anyone does wonder solved by changing the line to while ($k == 0;)
  5. Thanks for the response. I'd forgot to reset $k, so I put it after the $j reset, however it still did not solve the problem. I am aware of the ampersands and they have been put there on purpose due to other parts of the script. Any more ideas? If it helps $arr is an array of 10 numeric values, and $max is a single numeric value.
  6. Trying to code a first fit algorithm (explanation here). It doesn't output everything correctly at the end. There probably is an easier way to achieve this, but I need to do it using do and while statements. From the output I only get the first array, none of the others display. function first_fit(&$arr, &$max) { $bin = array(array(), array(), array(), array(), array(), array(), array(), array(), array() ,array() ); $i=0; $j=0; do { do { if (array_sum($bin[$j])+$arr[$i] <= $max) {$bin[$j][] = $arr[$i]; $k=1; } $j++; } while($k = 0); $i++; $j=0; } while($i<=9); outputarray($bin[0]); outputarray($bin[1]); outputarray($bin[2]); outputarray($bin[3]); outputarray($bin[4]); outputarray($bin[5]); outputarray($bin[6]); outputarray($bin[7]); outputarray($bin[8]); outputarray($bin[9]); } The function outputarray() just prints the array in a nicely formatted way. Any help would be much appreciated.
×
×
  • 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.