Jump to content

HuggieBear

Members
  • Posts

    1,899
  • Joined

  • Last visited

Everything posted by HuggieBear

  1. I've edited this post as I made a stupid commen t, as for the solution of letting MySQL do the work for you, akitchin has shown you how to do that below Regards Huggie
  2. Your syntax is slightly wrong, try this... [code]<?php if(!$_GET['stp']){ ?> <b>Welcome to the gem exchange.<br> <a href="gexchange.php?stp=ene">Exchange 5 gems for 100 energy</a><br> <?php } elseif($_GET['stp'] == "ene"){ if($user['uGems'] <= 4){ echo "You Dont have enough gems for this exchange."; exit;} else{ echo "You exchanged 5 gems into 100 energy"; $db->query("UPDATE users SET uAttackTurns=uAttackTurns+'100' , uGems=uGems-'5' WHERE uID='" . $user['uID'] . "'"); } } ?>[/code] When checking a string, use double quotes, so [code=php:0]if $var == "string"[/code] you had no quotes When comparing numbers, no need for the quotes so [code=php:0]if $var <= 4[/code] you had the 4 in quotes along with the less than sign. Regards Huggie
  3. Sounds like a job for an enterprise solution... Up steps Oracle :) Huggie
  4. OK, let me see if I've got this correct... The page loads, you click links on the page, this is meant to generate a random number using php and check if the random number is one of the needles.  If it is, it adds one to their total in the database and then redirects them to needle.php?view Regards Huggie
  5. It's very easy, look at these functions: For reading: [url=http://uk.php.net/manual/en/function.file-get-contents.php]file_get_contents()[/url] For Writing: [url=http://uk.php.net/manual/en/function.fopen.php]fopen()[/url], [url=http://uk.php.net/manual/en/function.fwrite.php]fwrite()[/url], [url=http://uk.php.net/manual/en/function.fclose.php]fclose()[/url] Regards Huggie
  6. In that case I don't think I've understood what you're after. As for getting me to try it, that page is riddled with errors.  I'd correct them first: [quote] Warning: main(../includes/inc-header.php): failed to open stream: No such file or directory in /home/fhlinux202/h/hcn-chat.com/user/htdocs/needle.php on line 3 Warning: main(../includes/inc-header.php): failed to open stream: No such file or directory in /home/fhlinux202/h/hcn-chat.com/user/htdocs/needle.php on line 3 Warning: main(../includes/inc-header.php): failed to open stream: No such file or directory in /home/fhlinux202/h/hcn-chat.com/user/htdocs/needle.php on line 3 Warning: main(): Failed opening '../includes/inc-header.php' for inclusion (include_path='.:/usr/share/pear') in /home/fhlinux202/h/hcn-chat.com/user/htdocs/needle.php on line 3 [/quote] Regards Huggie
  7. It's possible, and ideally you'd be better processing it in MySQL and then using an ORDER BY clause. Can you provide the method of working out the rating based on ratio? Regards Huggie
  8. This can be done using JavaScript... See [url=http://www.phpfreaks.com/forums/index.php/topic,107668.0.html]this post[/url]... I included some code Regards Huggie
  9. Use a header redirect after you've updated the database. [code]<?php if($rand==1 || $rand==20 || $rand==25 || $rand==56 || $rand==72 || $rand==100) { echo "Wow you found a needle. Keep looking and see if you can find more. Remember the more needles you find the better the chance of winning."; $db->query("UPDATE users SET uNeedle=uNeedle+'1' WHERE uID='" . $user['uID'] . "'"); header("Location: needle.php?view"); } ?>[/code] Regards Huggie
  10. Your code works fine for me... Using this: [code]<?php $search="php";  // I've hard coded $lines = file('data.txt'); foreach ($lines as $line_num => $line) {   if (preg_match('/('.$search.')/i', $line)) {     //echo "<br> Line ", $line_num, " matches: ",$matches[0],"<br>";     echo "$line<br>\n";   } } ?>[/code] And a data file that looks like this: [code] This is a test I like programming in php I love php CGI isn't easy PHP rocks Perl is better [/code] I get the following output: [code] I like programming in php I love php PHP rocks [/code] Regards Huggie
  11. Businessman, Back up your old code and then give this a try.  There's no real enhancements to the code, but it should work. [code]<?php // Start the session session_start(); // db connection info mysql_connect("localhost", "#####", "#####"); mysql_select_db("hasbadse_hbservice"); // Redirect if they aren't allowed to be here if ($_SESSION['controller'] != true){   header("Location: index.php"); } // If we don't have an ID then produce an error (I don't like this, but it's what you had it doing) if (!isset($_REQUEST['id']){   echo "You have arrived here from the wrong page\n";   die(); } // If the status is edit then update the table if ($_POST['status'] == "edit") {   $id = mysql_real_escape_string($_POST['id']);   $header = mysql_real_escape_string($_POST['header']);   $text = mysql_real_escape_string($_POST['text']);   $edit = "UPDATE usercms SET header = '$header', text = '$text' WHERE id = '$id'";   if (mysql_query($edit)){       echo "Edited Successfully.<br />";   }   else {       echo "There was a problem editing this entry.<br />";   } } // Select the data to display in the form $id = mysql_real_escape_string($_REQUEST['id']); $select = "SELECT * FROM usercms WHERE id = '$id'"; $query = mysql_query($select); $row = mysql_fetch_array($query); // Echo the form echo <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />   <title>Edit Your File Here</title> </head> <body>   <form name="edit" id="edit" action="{$_SERVER['PHP_SELF']}" method="POST">   <label for="header">Header:</label><br />   <input type="text" name="header" id="header" maxlength="100" value="{$row['header']}" /><br />   <label for="text">Text:</label><br />   <textarea name="text" id="text" rows="20" cols="20">{$row['text']}</textarea><br />   <input type="hidden" name="status" value="edit" />   <input type="hidden" name="id" value="{$row['id']}" />   <input type="submit" name="submit" id="submit" value="Continue" />   </form> </body> </html> HTML; ?>[/code] Regards Huggie
  12. Interesting use of both POST and GET, but not a problem... We can sort this for you. There's a few bits where I think you're over complicating it a bit, so we'll see if we can clear those up too. I'll get on the case now. Regards Huggie
  13. I think if you followed the W3Schools link in my signature and go through the SQL tutorial, you'd have the database up and running with your data in within two - three hours.  Once you have that done, we can help you with the rest I'm sure. Regards Huggie
  14. You haven't implied anywhere that your results are going to be on more than one page... Are they? Regards Huggie
  15. Try this then.... [code]<?php $groupheader = null; while ($row = mysql_fetch_array($result)){   $group = $row['main_group'];   if (is_null($groupheader) || strcmp($groupheader, $group) != 0){       $groupheader = $row['main_group'];       echo "<br>\n{$row['main_group']}<br>\n";   }   echo "{$row['item_name']}<br>\n"; } ?> [/code] You'll possibly need to change your SQL query. Regards Huggie
  16. So silk and wool are sub groups or main groups? Regards Huggie
  17. Can you provide me with your column names? Regards Huggie
  18. Glad to have been of assistance  ;) Huggie
  19. What parameters does this page get passed? Please provide all methods... GET/POST, COOKIES or SESSION. Regards Huggie
  20. Use the ORDER BY syntax in MySQL to get the stories ordered by date, and use the LIMIT syntax to restrict the number of requested rows. You can find a link to the MySQL manual in my signature. Regards Huggie
  21. This seems straight forward, but a quick question before we go any further... What's the difference between $currentpass and $oldpass? Regards Huggie
  22. Hi Amy, Don't worry about escaping simple variables in a double quoted string... Use this: [code] $critter = "BM05J10"; $sql = "SELECT `snakeID`, `date`, `weight` FROM `weights` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC"; [/code] Regards Huggie
  23. I'm assuming that you're passing true if successful and false if not addlink.php needs the following at the top... [code]<?php if ($_GET['update'] == "true"){   echo "Your update was successful\n"; } else if ($_GET['update'] == "false"){   echo "There was an error inserting your record\n"; } else {   echo "You did not submit a valid update option\n"; } ?>[/code] Regards Huggie
  24. Here's some information on zip from the [url=http://uk.php.net/manual/en/ref.zip.php]PHP Manual[/url] Regards Huggie
  25. I've amended my previous post too, as there's another change to make. Huggie
×
×
  • 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.