Jump to content

Barand

Moderators
  • Content Count

    19,633
  • Joined

  • Last visited

  • Days Won

    400

Barand last won the day on September 17

Barand had the most liked content!

Community Reputation

1,346 Excellent

5 Followers

About Barand

  • Rank
    Sen . ( ile || sei )

Profile Information

Recent Profile Visitors

58,264 profile views
  1. You shouldn't need the JSON.parse(data), you can use "data" directly EG $("#latitude").html(data.tpv[0].lat)
  2. The number you store in the database does not have to be the number you display to the user EG <option value="730"> 2 Years </option> As your options all appear to be a number of whole months (1, 3, 6, 12, 24) then I'd store the period as integer months. <option value="24"> 2 Years </option> You can then get the end date in SQL with SELECT start_date + INTERVAL contract_term MONTH - INTERVAL 1 DAY as end_date
  3. That particular subquery creates a temporary table called "last10" which contains your last ten records. See the link in my sig.
  4. Would the email also contain a token to confirm receipt?
  5. SELECT * FROM ( SELECT * FROM $tablename ORDER BY id DESC LIMIT 10 ) last10 ORDER BY RAND() LIMIT 1; (if recs have timestamp, use that to get latest 10 records)
  6. If you are happy with only the characters [0-9][a-f] The original uses the character set [0-9][a-z][A-Z]
  7. Agreed, you should let the user keep trying to register until eventually, in desperation, they try a different user name. At that point, when it works, they realize that the problem was a duplicate username. But at least, you didn't tell them.
  8. Just compare the two posted strings to make sure they entered it correctly, hash the password and save to the user table. You don't need password_verify at this stage - you use that when they log in with the username/password to verify at that stage that the entered password matches the stored (hashed) password. By default, PDO only emulates prepared statements. To use real prepared statements you need to turn off that default setting. My connection code is $db = new PDO( <db credentials> ); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // tell PDO to throw exceptions on error $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // stop emulating prepared statements
  9. I fails for a few historic dates $dt1 = new DateTime('2019-09-13'); $di = new DateInterval('P1M'); while ($dt1->format('Y') >= 1901) { if ($dt1->format('D j') == 'Fri 13') { if ( !isFridayThirteenth($dt1->format('Y'), $dt1->format('n'), $dt1->format('j') ) ) { echo $dt1->format('Y-m-d') . ' - Failed<br>'; } } $dt1->sub($di); } /* RESULTS : 2015-03-13 - Failed 2012-04-13 - Failed 2011-05-13 - Failed 2009-03-13 - Failed 2008-06-13 - Failed 2007-07-13 - Failed 2007-04-13 - Failed 2005-05-13 - Failed 2004-08-13 - Failed 2003-06-13 - Failed 2002-09-13 - Failed 2001-07-13 - Failed 2001-04-13 - Failed 2000-10-13 - Failed 1914-03-13 - Failed 1910-05-13 - Failed 1908-03-13 - Failed 1906-07-13 - Failed 1906-04-13 - Failed 1904-05-13 - Failed 1903-03-13 - Failed 1902-06-13 - Failed 1901-09-13 - Failed */ EDIT: P.S. Confirmed you're good until August 2100 2100-08-13 - Failed 2101-05-13 - Failed 2102-10-13 - Failed 2103-04-13 - Failed 2103-07-13 - Failed 2104-06-13 - Failed 2105-03-13 - Failed 2106-08-13 - Failed 2107-05-13 - Failed 2108-04-13 - Failed 2108-07-13 - Failed 2110-06-13 - Failed 2111-03-13 - Failed 2112-05-13 - Failed 2114-04-13 - Failed 2116-03-13 - Failed 2200-06-13 - Failed
  10. It depends on the collation setting for the column.
  11. Several things could be improved. 1 ) Do not use "SELECT * ". Specify the columns you need, in this case all you would need is count of matching records. 2 ) Having said that, searching for the username to see if exists before adding a new user is not the way to it. I don't know the structure of your users table but you should add a unique index on the username so it will throw an error if you try to add a second with same name. It is then only necessary to insert the new record try { insert new user } catch (exce[tion]) ( if exception is duplicate key error username error else re-throw error ) 3 ) Do not store passwords as plain text. Use password_hash() prior to storing and password_verify() when checking. When you connect using PDO, are you setting the emulate prepares attribute to false?
  12. Yeah, really sorry that my first reply wasn't what you wanted. But then again, the question you asked was nothing like what you wanted either and was a complete waste of time all round. And as I voulunteer my time here for free, I don't like having it wasted. If this wasn't what you wanted, learn how to ask better questions.
  13. I haven't a clue what $dizi is - it doesn't appear in your code. But if your ajax call is receiving a response like that in your code then the code below is an example of how to grab the data from it EG <?php if (isset($_GET['ajax'])) { // respond to the ajax request $resp = <<<EOF {"class":"POLL","time":"2010-04-05T21:27:54.84Z","active":1, "tpv":[{"class":"TPV","tag":"MID41","device":"/dev/ttyUSB0", "time":1270517264.240,"ept":0.005,"lat":40.035093060, "lon":-75.519748733,"alt":31.1,"track":99.4319, "speed":0.123,"mode":3}], "sky":[{"class":"SKY","tag":"MID41","device":"/dev/ttyUSB0", "time":"2010-04-05T21:27:44.84Z","hdop":9.20,"vdop":12.1, "satellites":[{"PRN":16,"el":55,"az":42,"ss":36,"used":true}, {"PRN":19,"el":25,"az":177,"ss":0,"used":false}, {"PRN":7,"el":13,"az":295,"ss":0,"used":false}, {"PRN":6,"el":56,"az":135,"ss":32,"used":true}, {"PRN":13,"el":47,"az":304,"ss":0,"used":false}, {"PRN":23,"el":66,"az":259,"ss":40,"used":true}, {"PRN":20,"el":7,"az":226,"ss":0,"used":false}, {"PRN":3,"el":52,"az":163,"ss":32,"used":true}, {"PRN":31,"el":16,"az":102,"ss":0,"used":false} ] } ] } EOF; exit($resp); // return the ajax response } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $().ready( function() { gondor() }) function gondor() { $.get( "" , // blank url - calls self {"ajax" : 1} , // data to pass to url function(resp) { $("#time").html(resp.tpv[0].time) $("#latitude").html(resp.tpv[0].lat) $("#longitude").html(resp.tpv[0].lon) $("#altitude").html(resp.tpv[0].alt) $("#hdop").html(resp.sky[0].hdop) $("#vdop").html(resp.sky[0].vdop) }, "JSON" ) } </script> <style type="text/css"> body { font-family: verdana,sans-serif; font-size: 12pt; padding: 20px 50px; } #output { width:60%; margin: 50px auto; border: 2px solid gray; padding: 30px; } .data {width:150px; display: inline-block; text-align: right; color: #369; padding: 8px; } label {width:150px; display: inline-block; text-align: left; padding: 8px; } </style> </head> <body> <div id="output"> <label>Time</label>:<div id="time" class="data"></div><br> <label>Longitude</label>:<div id="longitude" class="data"></div><br> <label>Latitude</label>:<div id="latitude" class="data"></div><br> <label>Altitude</label>:<div id="altitude" class="data"></div><br> <label>HDOP</label>:<div id="hdop" class="data"></div><br> <label>VDOP</label>:<div id="vdop" class="data"></div> </div> </body> </html>
  14. Try function unread_count( $id ) // pass id of receiver to the function { $stmt = $this->db->prepare("SELECT COUNT(*) as total FROM pm WHERE unread = 1 AND receiver_id = :id "); $stmt->execute( [ 'id' => $id ] ); return $stmt->fetchColumn(); }
  15. "$result->num_rows" is not PDO. The PDO equivalent is $stmt->rowCount(); You cannot mix mysqli calls with PDO calls. Manual - PDO (If you use SELECT COUNT(*) then only one row containing the count will be returned.)
×
×
  • 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.