Jump to content

xnowandtheworldx

Members
  • Posts

    89
  • Joined

  • Last visited

    Never

Everything posted by xnowandtheworldx

  1. Sometimes I had to use if(!empty($_SESSION['session_name'])) { //code here; } for some reason sometimes $_SESSION would be set, and would trigger a false positive. So try that out and hopefully it might help you out.
  2. Alright, since the depository is read only I'll just post this here . I had one hell of a time trying to figure out how I might be able to display variables via method chaining in PHP5 and I couldn't really find anything anywhere about it except for chaining methods, so...I decided to post this just in case someone else might be wondering . What am I talking about exactly? With the MySQLi class you can echo rows like so... $db = new MySQLi('localhost','username','password','database'); $q = 'SELECT * FROM table'; if($result = $db->query($q)) { while($row = $db->fetch_object($result)) { echo $row->mysql_column_name //this is what I'm talking about.... } } This is how I was able to do it... class ClassName { private $array; //set up a variable to store our array /* * You can set your own array or use the default one * it will set the $this->array variable to whatever array is given in the construct * How the array works like a database; array('column_name' => 'column_data') */ function __construct($array = array('fruit' => 'apple', 'vegetable' => 'cucumber')) { $this->array = $array; } /* * Loops through the array and sets new variables within the class * it returns $this so that you may chain the method. */ public function execute() { foreach($this->array AS $key => $value) { $this->$key = $value; //we create a variable within the class } return $this; //we return $this so that we can chain our method.... } } That's all there is to this example class, now on how to use it. $chaining = new ClassName(array('website' => 'phpfreaks.com', 'rating' => 'awesome!')); //set up echo $chaining->execute()->website,'<br/>'; //will print 'phpfreaks.com' followed by a break //or you could do it this way $vars = $chaining->execute(); echo $vars->website,'<br/>'; //will print 'phpfreaks.com' followed by a break echo $vars->rating; //will print 'awesome!' I hope this helps anyone that might be having problems this is the first tutorial I have ever tried to write lol, so I hope it's clear enough. Point out any errors, and any ways in which it might be able to be improved. Add on to it if you'd like.
  3. Try adding your session url variable to the header() function <?php if (!defined('WEB_ROOT')) { exit; } if (isset($_GET['StockID']) && (int)$_GET['StockID'] > 0) { $StockID = (int)$_GET['StockID']; } else { header('Location: ' . $_SESSION['login_return_url']); //THE CHANGE } $errorMessage = (isset($_GET['cstock_error']) && $_GET['cstock_error'] != '') ? $_GET['cstock_error'] : ' '; $sql = "SELECT * FROM fragrancestock WHERE StockID = $StockID"; $result = dbQuery($sql); extract(dbFetchAssoc($result)); ?> <p class="errorMessage"><?php echo $errorMessage; ?></p> <form action="processStock.php?action=modify" method="post" enctype="multipart/form-data" name="frmModifyStock" id="frmModifyStock"> <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr> <td colspan="2" class="title_text">Add Stock</td> </tr> <tr> <td class="label">Category</td> <td width="755" class="content"><? echo $Category ?> </td> </tr> <tr> <td class="label">Brand</td> <td class="content"><? echo $Brand; ?></td> </tr> <tr> <td class="label">Stock available</td> <td class="content"><?php echo $Quantity; ?> <input name="hidStockID" type="hidden" id="hidStockID" value="<?php echo $StockID; ?>" /></td> </tr> <tr> <td class="label">Current Selling price </td> <td class="content"><?php echo $SellingPrice; ?></td> </tr> <tr> <td class="label">Add new stock quantity </td> <td class="content"><input name="txtQuantity" type="text" value="" size="10" onkeyup="Modify_CheckQuantityField();" /></td> </tr> <tr> <td width="245" class="label">New Selling price per brand </td> <td class="content"><input name="txtSellingPrice" type="text" value="<?php echo $SellingPrice; ?>" size="20" onkeyup="Modify_CheckSellingPrice();" onclick="EmptyField();" /> (Change selling price here) </td> </tr> </table> <input name="btnAddStock" type="submit" id="btnAddStock" value="Add Stock" onClick="return checkModifyNewStock();" class="button_image"> <input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();" class="button_image"> </form> I couldn't really understand what you were saying, maybe a few more details as in which functions your calling in which you want the redirect to happen. I believe I got the gist of it, try it out and let me know.
  4. Ah sorry, well i took a look and it seems like you got it fixed. It seems like the error is that there was a space in the beginning of the actual text file. So basically all you should need to do is change $txtChunks = explode(' ', $contents); to $txtChunks = explode(' ', trim($contents)); that will remove extra whitespace from the beginning and the end.
  5. Here, I whipped this up in about 5 minutes it's probably not the best way to do it, but it will get the job done. I'll see what else I might be able to do with it. But note that this will only work as long as spaces aren't allowed in the names for the game. If spaces are allowed that users username will mess it all up, which is why this really isn't the best way to do it. If I come up with anything else i'll let you know. <?php $file = "foo.txt"; //specify the file to open $fh = fopen($file, 'r+'); //open up the file with read-only privileges $contents = fread($fh, filesize($file)); //we obtain the contents of the file for parsing $txtChunks = explode(' ', $contents); //we then turn the contents into a massive array using the spaces to seperate the words into "chunks" foreach($txtChunks as $text){ //we loop through our newly created array static $loop = 0; //set the loop counter to 0 and make it static so we know when to echo a break if($loop % 2 === 0 && $loop != 0) { //if the loop can be divided by 2 i.e. we have reached the end of the second word(the username) echo "<br/>"; //echo a break in the page } echo $text . " "; //echo out the text from the array $loop++; //increment our loop } ?>
  6. Your very welcome make sure to click the "Topic Solved" button at the bottom!
  7. Where exactly do you want the lines to end at? Can you possibly give us an example of what the .txt file looks like?
  8. Your doing your switch statement AFTER your calculating your total values try putting your switch statement below the $currency variable but above the $calcamt variable. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> </head> <body> <?php $amount = $_POST["amount"]; $currency = $_POST["currency"]; if(isset($_POST["amount"])) { switch ($currency) { case "GBP": $calccurr = 0.6397; break; case "CAD": $calccurr = 1.18659; break; case "EUR": $calccurr = 0.786225; break; case "AUD": $calccurr = 1.4653; break; } } $calcamt = $amount*$calccurr; if ($_POST["amount"] != NULL){ switch ($currency) { case "GBP": $calccurr = 0.6397; break; case "CAD": $calccurr = 1.18659; break; case "EUR": $calccurr = 0.786225; break; case "AUD": $calccurr = 1.4653; break; } echo "$amount $currency converts to $calcamt Dollars"; } echo <<<HEREDOC <form action='test.php' method='post'> <table width=400px height=650px cellspacing=0 cellpadding=3 border=0 align='center' > <tr> <td class='sub-title' colspan=2 style='height: 60px;' valign='center' align='center'> <b>Dollar Conversion Form</b> </td> </tr> <tr> <td colspan=2 style='height: 100px;'> </td> </tr> <tr> <td class='lable' valign='top'> Amount </td> <td class='txtbx' valign='top' align='left'> <input name='amount' type='textbox' maxlength='30' style="width: 200px;"> </td> </tr> <tr> <td valign='top' align='center'> <b>Select Currency Type</b> </td> <td><fieldset> <label>British Pounds<input type="radio" name="currency" value="GBP" /> </label> <br /> <label>Canadian Dollars<input type="radio" name="currency" value="CAD" /> </label> <br /> <label>Euros<input type="radio" name="currency" value="EUR" /> </label> <br /> <label>Australian Dollars<input type="radio" name="currency" value="AUD" /> </label> <br /> </td> </tr> <tr> <td colspan=2 style='padding-left: 25px;'> <input type="submit" name="submit" value="Calculate Value"> </td> </tr> <tr> <td colspan=2 style='height: 300px;'> </td> </tr> </table> </form> HEREDOC; ?> </body> </html> the above code should work fine. If you have any problems just let us know.
  9. Weird, placed it in another file, worked perfect, I guess its just an error in my syntax then, thanks for all your help I think I got it now!
  10. Still didn't fix it, and I have PHP displaying all my errors. :'(
  11. Well here's my current code, just like you asked. <?php $admin = true; $needToLogin = true; include '../includes/header.php'; if($_GET['step'] == 1 || empty($_GET['step'])) { echo " <form method=\"POST\" action=\"{$_SERVER['PHP_SELF']}?step=2\"> <table class=\"content\" align=\"center\" width=\"50%\"> <tr> <td align=\"right\">Objective amount:</td><td> <input type=\"text\" name=\"amount\" size=\"10\" /></td> </tr> <tr> <td COLSPAN=\"2\" align=\"center\"> <input type=\"submit\" name=\"continue\" value=\"Continue ->\" /> </td> </tr> </table> </form>"; } else { if($_POST['submit']) { foreach($_POST['objective'] as $objective) { $objectiveInsert .= $objective . ","; } foreach($_POST['amount'] as $amount) { $amountInsert .= $amount . ","; } foreach($_POST['type'] as $type) { $typeInsert .= $type . ","; } echo $objectiveInsert . "<br/>"; echo $amountInsert . "<br/>"; echo $typeInsert . "<br/>"; } echo " <form method=\"POST\" action=\"{$_SERVER['PHP_SELF']}?step=2\"> <input type=\"hidden\" name=\"amount\" value=\"$_POST[amount]\" /> <table class=\"content\" align=\"center\" width=\"50%\"> <tr> <td align=\"right\">Quest name:</td><td><input type=\"text\" name=\"name\" /></td> </tr> <tr> <td align=\"right\">NPC(id):</td><td><input type=\"text\" name=\"npc\" size=\"10\" /></td> </tr> <tr> <td align=\"right\">Reward type:</td><td> <select name=\"rType\"> <option value=\"Clicks\">Clicks</option> <option value=\"Item\">Item</option> <option value=\"Skill\">Skill</option> </select> </td> </tr> <tr> <td align=\"right\" onMouseover=\"ddrivetip('Item/skill name or click amount','black', 100);\" onmouseout=\"hideddrivetip();\"> Reward: </td> <td><input type=\"text\" name=\"reward\" size=\"10\" /></td> </tr> <tr> <td align=\"right\">Parent Quest:</td> <td><select name=\"pQuest\">"; $parentQ = $db->Query("SELECT * FROM `database`"); while($pQ = $db->Fetch($parentQ)) { echo "<option value=\"{$pQ['id']}\">{$pQ['name']} - TG? {$pQ['tg']}</option>"; } echo " </select> </td> </tr> <tr> <td align=\"right\">TG?</td> <td> <select name=\"tg\"> <option value=\"y\">Yes</option> <option value=\"n\">No</option> </select> </td> </tr>"; for($i = 1; $i <= $_POST['amount']; $i++) { echo " <tr> <td height=\"15\"> </td> </tr> <tr> <td align=\"right\">Objective $i:</td> <td><input type=\"text\" name=\"objectives[]\" /></td> </tr> <tr> <td align=\"right\">Amount $i:</td> <td><input type=\"text\" name=\"amount[]\" /></td> </tr> <tr> <td align=\"right\">Type $i:</td> <td> <select name=\"type[]\"> <option value=\"Killed\">Kill</option> <option value=\"Collected\">Collection</option> </select> </td> </tr>"; } echo " <tr> <td COLSPAN=\"2\"><input type=\"submit\" name=\"submit\" value=\"Add\" /></td> </tr> </table> </form>"; } include '../includes/footer.php'; ?> Just tested again, and when I have the form arrays in the code it will submit, but only return a white page, but if I remove them, it will submit fine, with my header/footer included, and the quest add form below, i've looked everywhere but just can not find what is stopping the script from executing. :\
  12. yes, I know that, I was just showing you how I actually parse it, I do echo all of the variables to the page. The problem is, if I have more than one form array, it will only display a white page, I tried turning on error reporting, and nothing.
  13. i'm having issues using multiple arrays within HTML forms. It's for adding quests for my game, and basically, there are 3 steps. 1. The admin goes to the page, enters the number of "objectives" for the quest. 2. They are brought to page with all the fields they need. 3. Form is submitted, and quest is added Basically my problem is, when the form is generated, say they wanted 3 "objectives" on the form the html for those "objectives" would be as followed.. <tr> <td height="15"> </td> </tr> <tr> <td align="right">Objective 1:</td> <td><input type="text" name="objectives[]"/></td> </tr> <tr> <td align="right">Amount 1:</td> <td><input type="text" name="amount[]"/></td> </tr> <tr> <td align="right">Type 1:</td> <td> <select name="type[]"> <option value="Killed">Kill</option> <option value="Collected">Collection</option> </select> </td> </tr> <tr> <td height="15"> </td> </tr> <tr> <td align="right">Objective 2:</td> <td><input type="text" name="objectives[]"/></td> </tr> <tr> <td align="right">Amount 2:</td> <td><input type="text" name="amount[]"/></td> </tr> <tr> <td align="right">Type 2:</td> <td> <select name="type[]"> <option value="Killed">Kill</option> <option value="Collected">Collection</option> </select> </td> </tr> <tr> <td height="15"> </td> </tr> <tr> <td align="right">Objective 3:</td> <td><input type="text" name="objectives[]"/></td> </tr> <tr> <td align="right">Amount 3:</td> <td><input type="text" name="amount[]"/></td> </tr> <tr> <td align="right">Type 3:</td> <td> <select name="type[]"> <option value="Killed">Kill</option> <option value="Collected">Collection</option> </select> </td> </tr> <tr> <td COLSPAN="2"><input type="submit" name="submit" value="Add" /></td> </tr> So, the form arrays are, objectives[], amount[], and type[], but when I got to submit it returns just a white page, but when I only have one array with the form, it's perfectly fine, can you not have more than one array with forms? One more thing, i'll post how I parse the arrays below. if($_POST['submit']) { foreach($_POST['objectives'] as $objective) { $objectiveInsert .= $objective . ","; } foreach($_POST['amount'] as $amount) { $amountInsert.= $amount . ","; } foreach($_POST['type'] as $type) { $typeInsert.= $type . ","; } } see any problems anywhere? Or are multiple arrays with forms not possible? Any help would be nice.
  14. woops I actually just changed the variable name $hour to $time so I wouldn't look like an idiot since that isn't an hour long time lol, but alright, i'll try the -360 one EDIT: And what-do-yah-know the $time = time() - 360 worked! Thanks! I appreciate it!
  15. Alright, well my site was recently hacked (due to a real stupid error on my part! includes and crons had full access! :X) and ever since then my logout button hasn't been working, I don't know what the problem is, but was wondering if any of you could help out? heres my code $time = -time() + 86400; setcookie('username', $_COOKIE['username'], $hour); header("Location: index.php"); do you see any problems with that? :\
  16. Even if I did that expression wouldn't i still have to remove the extra underscores? basically, what i needed was a regex command that would remove the _'s from the beginning and the end, and any double _'s there may be. Plus I don't know how to do a regex command for all the symbols...i need it for symbols !@#$%^&*()-+={[}]|\;;"'<,>.?/
  17. alright, i've got it fixed. Heres what i used. $string = preg_replace( "/\_{1,}/", "_", $string); thanks for all your help guys!
  18. I'm using str_replace() currently to replace all the special symbols. So how might I go about to check for multiple instances of the _'s with regex? Thank you for any help.
  19. Just ask your host if they can "point" your domain to another website. Or if your running cpanel under the "Domains" section there is a link titled "Redirects" and from there you can redirect your whole domain to another website. Hope that helps a little.
  20. Basically, I have a script where it takes a users input, and will replace !@#$% etc. etc. with an _. Now I need a regex expression that will remove all the extra _'s say for instance.... !hello*#world(*! would then be turned into "_hello__world___", now what I need to do is take that output and turn it into hello_world. Is there any possible way to do this with regex? I suck with regex, so any help would be nice! Thanks for any future help some of you may provide.
  21. Eh, just did some testing to see the highest number I could run..and I got up to 133,955,554 (that had to go through the process of factoring)...here are the results...
  22. Woahhhh...triple post lol. Take a look at this tutorial, it might help you a little bit. LINK
  23. Alright....so I was bored, and was looking through some student books I had, and decided to implement anything I could that had to do with math...this is actually for a math php class i'm making, but converted it to function for you guys to test out. I know it's probably not the best way to do it, but it took me about an hour 30 minutes to create, and it is by far one of the most complicated projects I have done, and i'm proud to have finished it(after pulling out a few chunks of hair of course). I wasn't able to upload it to my website at the moment(tired as hell) but feel free to test the code on your own! <?php //using preg_match to see if the number is prime function is_prime($number) { return !preg_match('/^1?$|^(11+?)\1+$/x', str_repeat('1', $number)); } //lets factor some numbers! function factor_number($number, $static_num) //we need a static variable "$static_num" to tell you the original number { static $factor = array(); //declare this static so the value won't change everytime the function is called if(is_prime($number) === FALSE) //if the number is not prime { for($i = 2; $i <= $number; $i++) //create our loop to find the first number it is divisible by { if($number % $i == 0) //if after division there are no remanders we found our first divisor { $factor[] = $i; //add the current $i number to our factor array so we can display the factored numbers later $number = $number / $i; //divide the number by the divisor if(is_prime($number)) //if the number is now prime we tack on the final number to make the multiplication correct $factor[] = $number; factor_number($number, $static_num); //if it's not prime, loop through until the number is prime break; } } } elseif(is_prime($number) === TRUE) //if the number is prime { echo "Number has been factored.<br/>"; //tell them the number was sucesfully factored echo "Factor for {$static_num} is: "; $array_count = count($factor); //count the array values for display foreach($factor as $key=>$value) { if($key != $array_count - 1) //if the current key of the array is not the last one, display the value with a multiplication sign { echo $value . " X "; } else //else its the last digit and we don't need the sign { echo $value; } } } } factor_number(9, 9); /* the function above displays... Number has been factored. Factor for 9 is: 3 X 3 */ ?> And I know the echo statements aren't the best choice for showing the results, but that's simple enough to change, just let me know what you guys think!
  24. Haha, thanks for all the help guys! I did try the '.' . $number; but it didn't work for me for some reason haha, but once again thanks for everyone that helped! It's greatly appreciated. Edit: Finally got the '.' . $number; working haha! Can't believe the first thing I tried actually works, been stressing over this for about an hour haha! But thanks ONCE againe.
  25. haha of course! Man i'm an idiot...sometimes the simplest things seems so much harder than they are haha. Thank you for your help everyone!
×
×
  • 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.