Jump to content

hsub

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by hsub

  1. hi all, i can't seem to figure out how to do this. below is a bit of code that sort through an array and return the 3 highest value. i would like to then take those three values and place them separately into the <div id> tags. <? $array = array(5, 8694, 13,5,46,84,9,48684,8642,54,3,664,87,93,24,56,487,9341,8432); rsort($array); for($i = 0; $i < 3; $i++) // Only loop 10 times. echo $array[$i] . "<br>"; ?> <div id="container"> <div id="left"> <?php echo $highest?></div> <div id="center"><?php echo $secondhighest; ?></div> <div id="right"><?php echo $thirdhighest; ?></div> </div> thank you in advance for any help on this.
  2. Hello again... I tried a separate to make sure that the files i am writing to are writable. They all work. However, when i run the entire script with the form, doesn't seem to what to open the file. Any ideas as to what's wrong. thank you again for all your help. <?php if ($_POST['message'] != "") { switch ($_POST['name']) { case 'Jamil': $file = 'message.txt'; break; case 'Razy': $file = 'message1.txt'; break; case 'Stephanie': $file = 'message2.txt'; break; } } ?> <?php if (!function_exists('file_put_contents')) { function file_put_contents($file, $contents) { $fh = fopen($file, 'w') or die("can't open file"); if(!$fh) { trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); return; } fwrite($fh, $contents); fclose($fh); } } if (file_put_contents($file, htmlspecialchars(stripslashes($_POST['message'])))) { echo "Your message was recorded"; } else { echo "An error occurred"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'> <p class="style2"> <select name="name"> <option>Jamil</option> <option>Razy</option> <option>Stephanie</option> </select> Message Updater: </p> <p class="style2"> <input type="text" name="message" /> </p> <p class="style2"> <input type="submit" Value="Build"/> </p> </form>
  3. This was the error i was getting and still am. I am quite new at this...so bare with me. Parse error: syntax error, unexpected T_STRING, expecting '&' or T_VARIABLE or T_CONST in /home/hsubr3/public_html/fbook/index3.php on line 24: function file_put_contents($file, htmlspecialchars(stripslashes($_POST['message']))) {
  4. Hi Hitman, thanks for such a quick reply and sorry for the headache. I should have taken better care is structuring the code. Will remember that next time i am seeking help from others. In any case, i'm in the processing of trying out your code and i'm running into an error. The error states.. Fatal error: Call to undefined function: file_put_contents() in /home/hsubr3/public_html/fbook/index3.php on line 28.. so i checked up on this, an you can only use file_put_contents() in php 5, my sever supports only 4.4.4. go figure. so i am look at the alternatives to this and found an the way you would work around if you didn't have php 5. So Now i have new errors which i can't seem to fix. I am looking, but thought i would speed things up by asking for some help. <?php // if (file_put_contents($file, htmlspecialchars(stripslashes($_POST['message'])))) { if (!function_exists('file_put_contents')) { function file_put_contents($file, htmlspecialchars(stripslashes($_POST['message']))) { $fh = fopen($file, 'w') or die("can't open file"); if(!$fh) { trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); return; } fputs($fh, $file); fclose($fh); } } echo "Your message was recorded"; } else { echo "An error occurred"; } } ?> any ideas on how to solve this.
  5. Hi everyone. I have 3 separate simple php forms, each with its own submit button, that are writing to a text file. Every time someone submits a message, that message is sent to a text file and the previous message in the text file is over written. This is what i want. The problem, however, is that when i submit one form and if a message has been sent previously with the either of the other two forms, each text file is over written. Essentially, what happens is that there are two blank text files, and one with the current message. I would like for the newest message to be kept in the two text files that are not being used each time someone choses a form to submit. Only the one chosen should be over written. thank you for any help on this.... Here is the code, i think this will probably help clarify what i am saying. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'> <p class="style2">Jamil Message Updater:<br><input type="text" name="name" /></p> <p class="style2"><input type="submit" Value="Build"/></p> </form> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'> <p class="style2">Razy Message Updater:<br><input type="text" name="name1" /></p> <p class="style2"><input type="submit" Value="Build"/></p> </form> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'> <p class="style2">Stephanie Message Updater: <input type="text" name="name2" /></p> <p class="style2"><input type="submit" Value="Build"/></p> </form> <? $myFile = "message.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); // $stringData = "Bobby Bopper\n"; fwrite($fh, $_POST['name']); fclose($fh); ?> <?php echo htmlspecialchars($_POST['name']); ?> <?$myFile1 = "message1.txt"; $fh1 = fopen($myFile1, 'w') or die("can't open file"); // $stringData = "Bobby Bopper\n"; fwrite($fh1, $_POST['name1']); fclose($fh1); ?> <?php echo htmlspecialchars($_POST['name1']); ?> <? $myFile2 = "message2.txt"; $fh2 = fopen($myFile2, 'w') or die("can't open file"); // $stringData = "Bobby Bopper\n"; fwrite($fh2, $_POST['name2']); fclose($fh2); ?> <?php echo htmlspecialchars($_POST['name2']); ?>
×
×
  • 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.