Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. so, you used a site/form creator that includes ads as part of its terms of use and you are trying to fix your site that broke when you attempted to get rid of the ads? it's not the purpose of programming help forums to help you bypass or disable features of software that you agreed to when you used that software. topic locked.
  2. there's no limit to the number of terms you can have. as pointed out, you likely had a typo and as also pointed out, you don't (ever) need to write out a statement that has that many terms in it.
  3. the particular message occurs when your massive isset(...) && isset(...) statement is false. the purpose of that statement is (should be) to test if a form was submitted. it doesn't need to test if every field is set, because all text/password/textarea fields will be set. so, just test if one field isset(), such as a hidden field that identifies that your registration form was submitted, which is what the $_POST['reg'] appears to be for. next, DRY (Don't Repeat Yourself.) You have a ton of code repeating the inclusion of the header/footer files. You should only have those ONCE. lastly, you should validate all the inputs at once and output all the errors at once so that the visitor doesn't need to repeatedly submit the form to find out each error in turn. your elseif() logic validating different fields should be completely separate conditional tests. to accomplish validating all the inputs at once, you would make an array to hold the error messages and then simply test if the array is empty at the end of all the validation. if it is empty, no errors. if is not empty, loop over the elements in the array and echo them to display the error messages.
  4. the answer to your question of can you use the logged in username (you should actually use the user's id, an auto increment column in your user table that corresponds to the user name, since this will be much faster than using a text string in queries. this is the id that trq mentioned in the first reply in this thread) as a filter in a query is yes, but this does require that you understand some basics about php, such as php variables, and to understand something about the code you are using, so that you know at what point in that code a variable exists. if your login script, which i am assuming is accessed via the session.php file, makes $login_session available, then you can only use $login_session after the point where you have included session.php. you have mentioned 'in dreamweaver' a couple of times. you do know that dreamweaver is just a tool, and a poor one when it comes to server-side php code. you should not be relying on a tool to do your work for you. a tool is something that you use to accomplish a goal.
  5. post the error message you are getting and post an example of an input data value causes the error.
  6. the reason for the error on the mysqli_fetch_all() is because it's another one of php's screw-ups that is only present in a specific case that you won't generally have any control over.
  7. are you 100% sure that the fetched array contains this 'missing' row? there are two possibilities - 1) you query is not matching that row, possibly because the where clause is false 2) your php code, doing things like testing for empty() values is skipping the display of that row, because an element of that row or of the join with the contact information resulted in empty or null values. if that row is in your fetched array, what does using var_dump() on that one row show?
  8. the syntax error is because your source code contains an error. you are using the Ternary operator on the line where the error is being reported. the Ternary operator doesn't use an if(). next, the best, general purpose method to use to highlight/change words in text, based on database entries would be - 1) get a unique list of words from all the content you are going to display on the page. this would require that you retrieve the rows from your pagination query. if you store these rows into an array, you can simply loop over this array later when displaying the information. as you are retrieving the rows from the pagination query, split them on the white-space/word boundaries and add all the words to an array. then use array_unique() to reduce this array to just the unique list of words. 2) using the unique list of words from step #1, run a query against your banned word table to get just the entries from that table that are found in the unique list of words from the content. you can implode the unique list of words and use WHERE word IN('word1','word2','word3', ...) comparison in the query. 3) retrieve the list of matching bad words into an array, then when you have the full list, implode that array using a | character. this makes a regular expression OR'ed pattern of all the found bad words. 4) as you loop through the content (the first array from step #1) to display it, you can use a preg_replace() statement, with the regular expression pattern from step #3, to find and replace any bad words with the replacement string.
  9. ^^^ except that the stated age of something depends on if the birthday has or has not occurred yet in the current year. the age is the difference in years, subtract one if the month and day are less than the current month and day.
  10. you have got to be kidding. since your only purpose here is to get someone to do this for you, topic locked. i recommend that you post in the freelancing/job offers forum section and hire someone to do this for you.
  11. parse errors that show up when moving between systems are usually due to using php's lazy short open <? tag, that's not portable between systems since it relies on a configuration setting, instead of using full opening tags <?php
  12. apparently, your Windows system has php4. the things you are trying to use, mysqli and PDO, were added to php in php5 and only exist in php5. if you are not going to use the at least the same MAJOR version of php that you used to developed your code, you shouldn't expect your code to run.
  13. the last ever update of php5.3 was just released. you should be using the latest php5.5 or 5.4, especially if you are learning php.
  14. the code base you found to use for your game is poorly written and NOT documented. it was originally written as part of a classroom assignment to learn basic programming, queries, and problem solving. it's not how a game would be written because it's not efficient , not organized, not secure, and doesn't use any 'best methods' of programming or html design. and since there's no useful comments in it, we don't have any idea which code is executed when "you get caught committing crimes such as stealing cars". in fact, there's noting in that code that contains any of those keywords in variables, queries, or comments. so, does the code you posted even contain any of the code that gets ran as the result of getting caught committing crimes? if YOU cannot determine and tell us which section of that code is the relevant section that is ran when "you get caught committing crimes such as stealing cars", WE cannot help you.
  15. no one here is going to try and figure out nearly 1300 lines of code, half of which is careless blank lines. you are going to have to at least narrow down the problem and post just the relevant section of code. i recommend that you start by looking for the correct rand(...) statement(s) that are involved with the action(s) you are asking about. once you find the correct place in the code, i recommend that you create defined constants or php variables that define/hold the values and put these values into a configuration file that gets included or in a settings database table that gets queried so that any time you need to make a change like you are asking about, you can do it in one consolidated place and not have to find and edit the actual code responsible for carrying out the operation. just about every hard-coded number in the code now, that determines a level, a reward, a random value, a time,... should be pulled out and made a defined constant or a php variable.
  16. your page controller is using a get parameter pg=file. the pagination logic is adding its own page and ipp get parameters. the easiest way of letting each different piece of your code independently manipulate the get parameters when building links is to use http_build_query(). if you search this forum for http_build_query, you will find a number of examples. basically, the pagination code will use any existing $_GET parameters (pg, search/filter terms...), set only the 'page' and 'ipp' values that it is responsible for, then build the query string to put onto the end of the links using the resulting set of combined data. some security issues in your code - 1) you should NOT use extract ($_REQUEST); this will allow hackers to set any of your program variables to anything they want. it also makes more work for you, the programmer, because you must now keep track of which program variables are magically appearing in your code, due to the extract(), to insure you don't overwrite anything, now or when you make changes to the code in the future. use the proper external variables ($_GET, $_POST, $_COOKIE) and forget about magically populating php variables. 2) your login check code needs an exit; statement after the header() redirect to prevent the protected code form running. without the exit;, all a hacker needs to do is ignore the redirect and he can still access your pages. 3) you MUST validate that the pg=file value is only a permitted, for the current visitor, and valid page. because you are using the value in an include statement, again, a hacker can include ANY file on your server, so he could include an administrative file, even though he isn't an administrator on your site. 4) in some versions of php, $_SERVER['PHP_SELF'] also contained the submitted query string, which can contain arbitrary cross site scripting code and should not be used or if used care must be taken when you echo it out on a page to render any html/javascript/css in it, inoperable.
  17. the error means that your query failed due to an error of some kind. you would need to use mysqli_error($con) to find out why.
  18. for your current information, the business logic to retrieve the data would be - $query = " SELECT igc.id, igc.giftCardName, igc.giftCardImage, igcc.currency, igcc.amount, igcc.pointsPrice, sum(if(igcc.status ='available',1,0)) as available, sum(if(igcc.status ='redeemed',1,0)) as redeemed FROM instant_gift_cards igc INNER JOIN instant_gift_card_codes igcc ON igc.id = igcc.giftCardId WHERE igc.status = 'Enabled' GROUP BY igc.id, igcc.amount ORDER BY igc.dateCreated DESC, igcc.amount"; $stmt = $db->query($query); $giftCard = array(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $giftCard[$row['id']][] = $row; } and the presentation logic would be - print" <table style=\"width:100%\" class=\"tableList\"> <tr> <th style=\"width:35%\">Prize Name</th> <th style=\"width:12%\">Amount</th> <th style=\"width:12%\">Points</th> <th style=\"width:12%\">Available</th> <th style=\"width:12%\">Redeemed</th> <th style=\"width:17%\">Action</th> </tr>"; if(!empty($giftCard)){ // there's at least one gift card to display foreach($giftCard as $arr){ // $arr is an array of arrays, one sub-element for each amount under each gift card $rowspan = count($arr); $first = 1; // a flag to detect the first pass through the following loop foreach($arr as $row){ // row will be the database row for each amount under one gift card echo "<tr>"; // start a row if($first++ == 1){ // output the one-time information here... if($row['giftCardImage']){ $nameOrImage = '<img src="./images/giftcardrewards/'.$row['giftCardImage'].'" alt="'.$row['giftCardName'].'" title="'.$row['giftCardName'].'">'; }else{ $nameOrImage = $row['giftCardName']; } echo "<td rowspan='$rowspan'>$nameOrImage</td>"; } // output the common data for each html table row here... if($row['available'] == '0'){ $redeemAction = 'Out of Stock'; } elseif($userInfo['currentPoints'] < $row['pointsPrice']){ $needed = $row['pointsPrice'] - $userInfo['currentPoints']; $redeemAction = 'You need '.$needed.' point(s)'; } elseif($userInfo['currentPoints'] >= $row['pointsPrice']){ $redeemAction = '<input type="button" value="Redeem" onclick="if(confirm(\'Are you sure to redeem this prize?\')){location.href=\'index.php?do=instantGiftCards&action=redeem&cardId='.$row['id'].'&amount='.$row['amount'].'\';}">'; } print"<td style=\"text-align:center\">".$row['currency'].$row['amount']."</td> <td style=\"text-align:center\">".$row['pointsPrice']."</td> <td style=\"text-align:center\">".$row['available']."</td> <td style=\"text-align:center\">".$row['redeemed']."</td> <td style=\"text-align:center\">".$redeemAction."</td> </tr>"; } } }else{ print" <tr> <td colspan=\"4\" style=\"text-align:center;color:#2B1B17;padding:15px 0\">No prizes added.</td> </tr>"; } print" </table>";
  19. here's a single (one) query that gets all the data your code currently is getting - SELECT igc.id, igc.giftCardName, igc.giftCardImage, igcc.currency, igcc.amount, igcc.pointsPrice, sum(if(igcc.status ='available',1,0)) as available, sum(if(igcc.status ='redeemed',1,0)) as redeemed FROM instant_gift_cards igc INNER JOIN instant_gift_card_codes igcc ON igc.id = igcc.giftCardId WHERE igc.status = 'Enabled' group by igc.id, igcc.amount ORDER BY igc.dateCreated DESC, igcc.amount another comment about what you are currently doing - you are repeating the currency, amount, and pointsPrice in each same amount row in your instant_gift_card_codes table, for each code under any giftCardId. you should have another table that holds only one copy of the currency, amount, and pointsPrice information. your instant_gift_card_codes table would then only have an id, the id of the corresponding row in this new table, the code, and the status - available/redeemed.
  20. to do what mogosselin has suggested, you will need to pre-process the data that the query returns, making an array of arrays, where the main array index is the instant_gift_cards id. then as you are looping through the different instant_gift_cards to display them, you can use count() on the sub-array for each instant_gift_cards to find out the rowspan value. in order to do this, you must first separate the business logic that's getting the data, from the presentation logic that's displaying the data. you should be able to put a comment in your code, above which is only php and database query logic, without any html/css/javascript.. and below which there is no database specific code, just php variables, loops, echo/print statements... that produces the html/css/javascript based on the data that was retrieved by the business logic. you also need to NOT run queries inside of loops. you can write one query that gets all this information at once (time permitting, someone will probably post an example.) edit: also, for static/program produced values, like your status = 'Enabled', there's no point is using a prepared query for that. just build the query with the value in it. place-holders in queries are for data that must be escaped/cast to prevent errors or to prevent sql injection and for queries that will be executed more than once with different values. you queries will also be easier to write and read if you use alias names for the tables being referenced.
  21. we can only help you with your code after you have posted it and we also need to know exactly what output you expected and what output you did get, because telling us what did happen, even if it's a completely blank page, is as important as knowing what didn't happen when troubleshooting programming.
  22. store the data in a database. a) you can set up indexes that allow information to be found quickly, without reading through the whole set of data. b) the database engine is complied code that can find information at least 10x faster than php's interpreted code can.
  23. no matter how high you set the values, someone can and will come along and try to upload larger files than the settings allow. your code should test for upload errors and report back to the visitor when individual files (determined by the upload_max_filesize setting) and when all the form data (determined by the post_max_size setting) has been exceeded.
  24. how do you know that? what sort of symptom or error do you get? there's a dozen different things that could prevent an upload from working, starting with the form not having the needed enctype attribute all the way through to file/folder permissions preventing move_uploaded_file() from being able to move the file to the destination folder. is your code even testing if the file got uploaded without any errors, before trying to use the uploaded file information?
  25. the emails are being sent FROM your mail server at bluehost. the domain in the from address needs to correspond to the sending mail server, i.e. you have set up dns zone records under your account that the receiving mail server can use to confirm that the sending mail server where your domain is hosted at IS where the mail should have been sent from. if you want to include the sender's email address, for reply purposes, you put it into a Reply-to: mail header, not the From: header.
×
×
  • 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.