Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by Sepodati

  1. Unless your doing something to the data before it goes into the database, all those newlines are there. So as mentioned, the problem is probably when you display. nl2br() will help here, but you should also use htmlentities(). This will ensure anything typed into the box is displayed exactly as typed and not evaluated as HTML. echo nl2br(htmlentities($row['description'])); The takeaway here is that you process the data for where it's going. If it's going on the database, process through a prepared statement. If it's going into an HTML document, process it as above. If it's going into email, maybe there's another processing. etc, etc. Process for where it's going at the time it goes there. i.e. don't prices for HTML as it goes into the database. Hopefully that helps.
  2. Never store anything relating to bank information yourself. Use something like Stripe. I'm sure there are others, but that's the one I'm familiar with.
  3. $data_array[$salesByCode["prod_code"]] = $salesByCode; $_SESSION["onhold_cart_items"] = $data_array; can be replaced with: $_SESSION["onhold_cart_items"][$salesByCode["prod_code"]] = $salesByCode;
  4. Fix your data BEFORE it goes in the database so you don't have to do all that ltrim, rtrim, replace crap on the way out. As for the loop, either check that there are rows returned, as mentioned above, or use this method: if($row = odbc_fetch_array($result)) { echo "<table><tr>"; echo "<th>CustID</th>"; echo "<th>OrderId</th>"; echo "<th>Amount</th>"; echo "<th>TotalAmount</th></tr>"; do { echo "<tr><td>{$row['cust_num']}</td>"; echo "<td>{$row['name']}</td>"; echo "<td>{$row['city']}</td>"; echo "<td>{$row['state']}</td></tr>"; }while($row = odbc_fetch_array($result)); echo '</table>'; } else { echo 'No results found.'; }I don't like echo'ing HTML and you'd probably want to use htmlentities() if you're not doing any sanitizing of the data before it goes in. but that should give you a structure idea.
  5. The server can't unzip files on the client. That doesn't make any sense. You could offer them up for download. Then once downloaded, the user can unzip them on their own (client) machine.
  6. Also, within the foreach() loop, if you continue that way, you shouldn't have to refer to the array you're looping through. $pn["prod_name"] is the same thing as $data_array[$kp]["prod_name"], on each iteration through the loop. That's the point of the foreach: $kp and $pn change each time through the loop, for each element of $data_array. As said, if the only thing you're doing is populating the $_SESSION, then just do that directly in the retrieval loop.
  7. Because nothing does. Learn HOW to read the manual and this becomes clear. That says explode() expects 2 or 3 parameters. The third parameter is optional, since it's enclosed in brackets. That also tells you that IF you pass a 'limit' parameter, it must be something that evaluates to an integer. IF you do not pass a value, then the limit will be set to the default value contained in the constant PHP_INT_MAX (9223372036854775807). All of these produce the SAME EXACT result from explode(): <?php $text = "This is a simple sentence to explode into parts"; define('LIMIT_CONSTANT', 3); $limit_string = '3'; $limit_int = 3; echo "Using Literal:\n"; var_dump(explode(' ', $text,3)); echo "Using Constant:\n"; var_dump(explode(' ', $text, LIMIT_CONSTANT)); echo "Using String Variable:\n"; var_dump(explode(' ', $text, $limit_string)); echo "Using Integer Variable:\n"; var_dump(explode(' ', $text, $limit_int)); ?> I don't know why I'm still helping you, though. I guess I hope that someone will come along that can actually learn and this may be useful to them.
  8. Seeing you reference an 'SDB' element of the data, which isn't there, leads me to believe the data in those blocks can change? In that case, creating a query within reach loop, with the relevant columns, would be best. Which method is better or worse is all relative... Do whichever makes sense to you. John
  9. Easiest way would be to create and execute a query each time you find the data you're after. You could also create a single query in the format of INSERT INTO table () VALUES (...),(...),(...); building each (...) set of data in your loop.
  10. Yeah, you're not really dealing with JSON. It's all PHP arrays when you decode it like that, which is fine.
  11. The way you've decoded it, $data['data'] is an array. The first four elements (0-3) are those {"$ts": 170801170000,"$msg": "WDT;LWS"} entries. Each {} and whatever is in it is an element of the data[data] array. The fifth Element (key 4, arrays start at zero) is the actual data you're after. Knowing that, will the data always start at element 5? Or could there be more or less of the $ts/$msg elements? (EDIT: Just saw your edit. The code below will still work.) One idea is that you could loop through $data['data'] with a foreach ($data['data'] as $value). Check if isset($value['RH']) and if it is, you're in an element with data. Check this out: https://3v4l.org/K7iU1
  12. Have you confirmed PHP is working at all? Make a file with just the following in it called info.php and place it in your web directory. <? phpinfo(); ?> Then load http://localhost/info.php or whatever the path should be. Does that generate a PHP info page?
  13. Are you sure that's the right code? $data['data']['RH'] doesn't exist, based on that JSON file. $data['data'][4]['RH'] does. The fourth element of $data['data'] has all of those values. Is that what you mean by having to modify the JSON heavily? When you say the file could have more data "rows", what do you mean? There'd be more of these: { "$ts": 170801170000, "RH": 67.15, "AT": 12.87, "MINVi": 3.81, "PTi": 23.4, "LWS": "0*T", "WSAV": 0, "WSMX": 0, "WSMN": 0, "PR_TOT": 156, "RAIN": 0, "FDI": 0.239, "DT": 2.881, "WD": "0*T", "P1": "0*T", "AVGCi": 175 } One after the other, or what?
  14. First of all, you don't need to include('search.php') in your file. autocomplete makes an HTTP request to 'search.php?term=xxx' and expects a JSON object back. If you're finding no rows, you're not returning a JSON object. So autocomplete doesn't know what to do with the data. You could return a json object like echo json_encode(array('No data'));, but that's going to make it an option the user can select. You may want to work out some different logic here. If nothing is returned, unhide a "no matches" span next to the box or something.
  15. https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
  16. what's your table schema? Where's the query that you're running? If it's MySQL, this is the first thing that came to mind, for me:
  17. Where does the field get updated? Is this all in a database and that field gets updated or is it a field on an HTML page? (or both, if one feeds the other?)
  18. Before you do your writing, get all of the file contents with file_get_contents() and then use strstr() to see if $_POST['email'] is in the contents you read. Only if it isn't, then open and write the email address to the file.
  19. The question mark after the "s" makes it optional. So both http and https are covered. -John
  20. Those are two of many vectors. Simply using them doesn't make anything inherently secure.
  21. If you ignore PHP for a second, and shorten things up, this is what you want: <a href="e.com"><img src="cat.jpg" class="img-tipso" data-tipso-title="title" data-tipso-content="<img src='a.jpg'/>"> The two > symbols at the end each close one of the <img> tags. That's why you need two, one inside the double quotes and one to close the actual <img src="cat.jpg">. Now to take that into PHP, as mentioned before, you just add escape characters before the single quotes if it's enclosed by single quotes. echo '<a href="http://www.example.com"><img src="cat.jpg" class="img-tipso" data-tipso-title="title" data-tipso-content="<img src=\'a.jpg\'/>">';
  22. https://3v4l.org/VJoGS echo '<a href="http://www.example.com" target="_blank"><img src="http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src=\'http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg\'/>">';
  • 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.