Jump to content

FreakingOUT

Members
  • Posts

    56
  • Joined

  • Last visited

Everything posted by FreakingOUT

  1. OOOOOPS... And in conjunction with this in the page header...: <meta http-equiv="refresh" content="3600"> ... the desired content *should* always display automatically as desired and can easily be changed. No, that would limit the page refresh to one time per hour... DUH! Excuse the bandwidth. -FreakingOUT
  2. Hello, Barand: Once again you have kindly come to my rescue! As I was pouring through multiple lines of code in various function examples trying to figure out some type of 'reverse engineering', everything became a blurrrr on only 2 hours of sleep. Now I am blown away (again) by the simplistic elegance of your concise solutions. Another learning experience for me! I tested both and really appreciate the two options you provided. Using $pastdatetime in the PHP code will keep what is already a very lengthy $sql querey shorter. And in conjunction with this in the page header...: <meta http-equiv="refresh" content="3600"> ... the desired content *should* always display automatically as desired and can easily be changed. Thank you very, very much !!! -FreakingOUT <- (No more in this time related matter :^)
  3. I've been researching online resources and seen a lot of code and functions for calculating an interval or difference between two date/time figures. What I'm trying to do is somewhat in reverse... I want to establish an interval to determine a past date/time to be used in a MySQL Query but just can't figure the critical part. // STEP #1 = DEFINE THE DESIRED DATE/TIME DIFFERENCE INTERVAL DESIRED FOR QUERIES $timeinterval = '60'; // Interval is in MINUTES and can be changed as desired // STEP #2 = GET THE CURRENT LOCAL SERVER DATE/TIME // as YYYY-MM-DD HH:MN:SE $serverdatetime = date('Y-m-d H:i:s'); // My local Server Date & time // STEP #3 = CALCULATE THE ***PAST** (OLDER) DATE/TIME LIMIT BASED ON $timeinterval (Minutes) // as YYY-MM-DD HH:MN:SE $pastdatetime = [stuckinarut here] <- 60 MINUTES prior to current Server Date/Time // STEP #4 = MySQL QUERY (`submitted` column is auto-timestampped on record insertions) $sql="[columnsblahblah] FROM mydb WHERE `submitted` >= $pastdatetime"; In a Perfect World, the MySQL Query would yield ONLY records with a `submitted` DATE/TIME equal to 60 Minutes (or less) PRIOR TO from the Current Server Time. Any assistance is appreciated! Thanks. -FreakingOUT
  4. Thanks very much guys for the considerable Educational Enlightment here. Now my eyeballs are REALLY rolling :^) I reallly appreciate the feedback and insights. -freakingOUT
  5. I'm stuck at trying to figure out out to complete the 3 Step scripts to accomplish passing $variables between 2 different servers. Since there will actually be 12 Non-POST $variables involved in the SERVER #1 to SERVER #2 transfer , it doesn't appear that trying to put these all in a URL string and going the 'GET' route is practical. I'm just using 3 short test variables in the examples. My eyeballs started rolling within I ran across something about 'CURL' that might be a necessary part of the solution? The code I have been able to hammer out so far is below as STEP 1, STEP 2 and STEP 3. STEP 1 <?php // submit.php // STEP 1 // On (LOCAL) SERVER #1 TO relay $variables to 'process.php' on (REMOTE) SERVER #2 // To submit $variables to directly another destination server script // NOTE: The $variable are NOT the result of Form Input !!! // For login Authenticaion ALL 3 must match db entries on SERVER #2 // NOTE: (Again) The $variables are NOT the result of Form Input !!! $userid = "adam"; $passwd = "eve"; $pscode = "peterpan"; // NOTE: (Again) The $variable are NOT the result of Form Input !!! // These $variables are needed for MySQL db INSERT on the destination URL server // For testing simplicity (actual data will be 12 $variables) $a = "apple"; $b = "banana"; $u = "1234567; // // Not sure if something called 'CURL' is needed here ??? // $submit_to_url = http://www.blahblah.com/process.php"; ?> STEP 2 <?php // processor.php // STEP 2 // ON SERVER #2 TO RECEIVE DATA DIRECTLY FROM SERVER #1 'submit.php' // To receive and process the $variables into a MySQL db on SERVER #2 // NOTE: The $variables are NOT the result of Form Input !!! // First validate $userid, $passwd & $pscode against `verify` table MySQL records require '/SERVER_2_securelocation_for_database_connection/secret_mysqli.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // // Not sure if something called 'CURL' is needed here ??? // // These login $variables are from submit.php on SERVER #1 $userid $passwd $pscode $sql="SELECT `userid`, `passwd`, `pscode` FROM `verify` WHERE `userid` = '$userid'" AND `passwd` = '$passwd` AND `pscode` = '$pscode'; $result = mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } // // Then some Authentication code if ALL 3 components match // // If Authentication = true then $passed = "YES" must sent // be sent back to the 'finalstep.php' script on SERVER #1 // If Authentication (or connection) = false ... $passed = "NO" $return_to_url = http://www.blahblah.com/finalstep.php"; // These $variables are from submit.php on SERVER #1 $a = "apple"; $b = "banana"; $u = "1234567"; $sql="INSERT INTO `data` (`a`, `b`, `u`) VALUES ('$a', '$b', '$u')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } // If $SQL INSERT into `data` on SERVER #2 works ... // $status = "Pending" must be sent back to the 'finalstep.php' // script on SERVER #1 for MySQL db Table insertion // If $SQL INSERT into `data` = false, then $status = "Error" // NOTE: The '$u' $variable also needs send back to finalstep.php !!! $return_to_url = http://www.blahblah.com/finalstep.php"; mysqli_close($con); ?> STEP 3 <?php // finalstep.php // STEP 3 // ON SERVER #1 TO RECEIVE DATA DIRECTLY BACK FROM SERVER #2 process.php // To receive the $passed, $status and $u $variables for final step action // NOTE: The $variable are NOT the result of Form Input !!! require '/SERVER_1_securelocation_for_database_connection/secret_mysqli.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // These $variables are from process.php on SERVER #2 $passed $status $u $sql="UPDATE `tracking` SET `passed` = '$passed', `status` = '$status' WHERE `uniqueid` = '$u' "; $result = mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); ?> Thanks very much for any assistance and guidance. -freakingOUT
  6. I spent several hours trying to figure this thing out. Thought I had it nailed, but still getting duplicate record entries into the MySQL DB when I do NOT want them. Here's the plot: People filling out the possible attendance form for a Ham Radio event *sometimes* bring a 2nd person (either a spouse or a friend). The 2nd person may, or may not, also has a Callsign which I need to put INSERT the same MySQL Callsign column. In any event, to also identify the 2nd person as coming 'with' the 1st person. MOST of the attendees are individuals with NO 2nd person. My entry form has these primary fields: callsign fullname AND... callsign2 fullname2 What I came up with was to process the MySQL INSERT for the primary callsign & fullname into their respective MySQL DB Columns (which works fine), and then........... immediately following the main Query INSERT, to do a substitution type thing depending on whether or not a form entry was made in the callsign2 field, AND/OR, the fullname2 field. This partially works, but if there is ONLY a primary callsign and fullname in the form, I'm still getting a duplicate record entry which includes the callsign in the `with` column (which should ONLY take place IF there is a 2nd person indicated). Confusing? Here is what I have been wrestling with to try and accomplish the objective, and now my eyes are glazed over ;-( // TRICKY PART HERE // If a 2nd Callsign AND a Fullname if ($callsign2 != ' ' && $fullname2 != ' ') { // Still make reference to the primary Callsign in the MySQL DB `with` column $with = $callsign; // Assignment to allow 2nd Callsign to be entered in the MySQL `callsign` column $callsign=$callsign2; $fullname=$fullname2; $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign', '$fullname', '$with')"; // If NO 2nd Callsign BUT a Fullname } elseif ($callsign2 = ' ' && $fullname2 != ' ') { // Make reference to the primary Callsign in the MySQL DB `with` column $with = $callsign; $callsign=$callsign2; $fullname=$fullname2; $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign', '$fullname', '$with')"; } else { // The only thing I could thing of to (hopefully) NOT make a 2nd entry // record in the MySQL DB IF there is NO 2nd person referenced $with = $callsign; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } This mostly works EXCEPT if only a single (primary) person entry. The recap the objetives: 1. If ONLY a primary/single person entry on the form: * callsign & fullname get INSERTed into the `callsign` and `fullname` columns in the DB as ONLY one record entry 2. If BOTH a primary and 2nd person on the form: A. IF the 2nd person has a Callsign, then the 2nd record entry would be: * callsign2 & fullname2 get INSERTed into the `callsign` & `fullname` columns in the 2nd DB as a separate record entry * callsign of the primary person also gets INSERTED into the `with` column in the same 2nd DB record entry B. IF the 2nd person does NOT have a callsign, then the 2nd record entry would be: * fullname2 gets INSERTed into the `fullname` column in the DB as a separate 2nd DB record entry * callsign of the primary person also gets INSERTED into the `with` column in the same 2nd DB record entry I obvioiusly have overlooked something, but just can't seem to figure it out at this point {SIGH}. Thanks for any enlightenment. -FreakingOUT
  7. Thank you so very much, Ch0cu3r ... it works !!! Yes, I know, I need to clean things up with CSS. - FreakingOUT
  8. I must be mixing apples and oranges here or something trying to get two columns/fields of MySQL data to display. The basic HTML page display OK and there are no MySQL Connection errors (finally resolved those). <HTML snipped> <?php require '...<URL snipped>...'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT `name`, `id` FROM `roster`"; $result = mysqli_query($con,$sql); $num=mysqli_num_rows($result); mysqli_close($con); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td> <font face="Arial, Helvetica, sans-serif">NAME</font> </td> <td> <font face="Arial, Helvetica, sans-serif">ID</font> </td> </tr> <?php function mysqli_result($res, $row, $field=0) { $res->data_seek($row); $datarow = $res->fetch_array(); return $datarow[$field]; } $i=0; while ($i < $num) { $f1=mysqli_result($result,$i,$datarow[$field]); $f2=mysqli_result($result,$i,$datarow[$field]); ?> <tr> <td> <font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font> </td> <td> <font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font> </td> </tr> <?php $i++; } ?> </table> <?php ?> <HTML snipped> Any assistance is appreciated. Thanks very much. - FreakingOUT
  9. Yes, I checked the page source and then thought *maybe* I needed to put the (require '<snip partial URL>mysqli.php' statement at the front starting with the PHP tags and ending the page with the PHP tags. It worked! I had mistakenly assumed that the PHP code (encapsulated in the PHP tags) inside the HTML would work. Another "Senior Moment", as now recall having done things this way in the past. My bad ;-( Thanks for the reminder as well. - FreakingOUT
  10. P.S. I also tried embedding the PHP script WITHOUT the other <table> structure in the .html file, and get this: CALLSIGNQTHLOG SUBMITTED "; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['callsign'] . ""; echo "" . $row['qth'] . ""; echo "" . $row['submitted'] . ""; echo ""; } echo ""; mysqli_close($con); ?> Ugh ;-( - FreakingOUT
  11. PHP = 5.5.14 MySQL = 5.2.17 This simple .php script works as a standalone OK: <?php require '<snip partial URL>mysqli.php'; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT `callsign`, `qth`, `submitted` FROM `lqplogs` ORDER BY `callsign`"); echo "<table> <tr> <th><u>CALLSIGN</u></th><th><u>QTH</u></th><th><u>LOG SUBMITTED</u></th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['callsign'] . "</td>"; echo "<td>" . $row['qth'] . "</td>"; echo "<td>" . $row['submitted'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> A separate .html page with other info works by itself OK too, but when I try to embed the PHP script (with PHP start & end tags, of course) *between* these HTML tags: <table> <tr> <td> ... Full PHP Script Embedded here... </td> </tr> </table> I get this mess: "; while($row = mysqli_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo " CALLSIGN QTH LOG SUBMITTED " . $row['callsign'] . " " . $row['qth'] . " " . $row['submitted'] . " "; mysqli_close($con); ?> Any thoughts as to why are appreciated. Thanks! - FreakingOUT
  12. Thanks for the notepad++ tip. Years ago I used Dreamweaver which worked well and recently tried a PHP Editor trial install that didn't work out too well. GREAT NEWS... I know cleaning up the copy & paste was part of the solution as you recommended. I decided to go-for-the-Gold and via myPHPAdmin created the full blown 32 column table I end to use (there will only be about 100 records total, so dispensed with splitting into separate tables & Foreign Keys for this one). Further modified the submit & insert scripts (and mysqli_connect 'require' file) and took a new Test Drive. Here was the result out-of-the-gate: 1 record added BINGO :^) I had tried to delete the Primary Key in the other database via myPHPAdmin, but the ALTER command kept wanting to add it back in ;-( Thanks again for your assistance !!! - FreakingOUT
  13. No html/xml markup. I'm using NotePad & WordPad {SIGH}, and SmartFTP for uploading to the server (I use this no problem with many other files). On a whim, I did another pass at deleting/retyping stuff, and now got these error messages: Warning: mysqli_connect() [function.mysqli-connect]: (42000/1044): Access denied for user 'myname@'localhost' to database 'myuid_test' in /home/myuid/mydomains/in myrequirefile.php on line 3 Failed to connect to MySQL: Access denied for user 'eric'@'localhost' to database 'myuid_test' Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in <snip> on line 13 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in <snip> on line 19 Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in <snip> on line 20 Error: The "access denied" rang a bell about some past .php file access to the particular database where I added the new Test Table (but not problems accessing or using it via myPHPAdmin). So I modified the html & php scripts to attempt an INSERT of a single variable into a *different* test database & Table that I can read test data from and now got this Error: Error: Duplicate entry '' for key 'PRIMARY' At least I'm now connecting to something without the initial Line 2 Errors, but with NO idential/duplicate entry in what I tried to Insert, need to figure out what's going on. I did a Google search and found a bunch of explanations which included droping the Table and re-creating, but for several reasons that would be a major hassle at the moment. I'll keep digging. Thanks, mac_gyver! - FreakingOUT
  14. Yes, the missing " error was corrected - sorry. I did more research about the error and made sure to delete any trailing spaces, etc. from the copy & paste. Just re-typed the first 2 lines as you suggested in hopes that might solve the problem, but still get the same Error Message. Baffling ;-( - FreakingOUT
  15. Got a couple hours of sleep and just corrected <html: to <html> in the submit script, but still getting the Error Message. - FreakingOUT
  16. PHP = 5.5.14 MySQL = 5.2.17 I've cloned a mysqli_connect() statement in a 'require' file placed in a non-public access location on the server. It's the same format (and location) currently working fine with another application, EXCEPT i changed the database name to what I need to use for this application, AND added the $con= part on the front end to substitute for the commented out $con= line in the example code I'm modifying to insert data into a new MySQL DB Table. The dB Table is fine and I have Inserted data via myPHPAdmin with no problems. Only two form variables are in the simple PHP script thus far just to test if it will work before proceeding. I've used pseudonames for the actual /home/.... location and filename, and am now Baffled about the Line 2 Error Message I'm getting (below the code). <?php require '/home/myusername/domains/mydomain.com/myclonedrequire.php'; //$con=mysqli_connect("example","uid","pwd","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $year = mysqli_real_escape_string($con, $_POST['year']); $callsign = mysqli_real_escape_string($con, $_POST['callsign']); $sql="INSERT INTO `lqplogs` (`year`, `callsign`) VALUES ('$year', '$callsign'); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?> ERROR Message: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in (above file & location) on line 2 There are NO '\' characters in any of my files. Here is the simple Form file code: <?php ?> <html: <head><title></title></head> <body> <form action="insert.php" method="post"> YEAR: <input type="text" name="year"> CALLSIGN: <input type="text" name="callsign"> <input type="submit"> </form> </body> </html> <?php ?> Thanks for any assistance! -FreakingOUT
  17. Three questions: 1. Each record fed into an array by the Parser will yield 8 fields (columns) of data totalling about 50 characters per record. So if I upload & parse 5,000 records in one batch, do you think that is doable? I guess it also depends on my ISP's server & RAM, etc.? There is a possibility at some point a particular file *could* be as large as 20,000 records... or in one case, even 50,000 records, but those would be the exceptions. 2. The Date field data comes out of the Parser like "20140208", instead of the "2014-02-08" format I had planned to use. However, there will be a need for users to verify a MM and DD for specific records, so is one format flavor more desirable for this purpose than the other? 3. The Time field data comes out of the Parser like "181519" (HHmmss), and the same question .... would this be easier for time similar verification purposes than "18:15:19" (the acceptable range would be within one-hour either side of what is in the field) ??? Where things get dicey is if the Parser output Date/Time is something like 2013-12-31 & 23:45:15, but for verficiation purposes (if someone's clock was off by ~ one hour), would need to accept 2014-01-01 & 00:44:14 (if I mentally and on fingers did that right :^) Thanks very much. -FreakingOUT
  18. OOOPS... correction... This is the one that works: $sql = "INSERT INTO `qsolog` (`callsign`) VALUES ('" . $record["call"] . "' )"; -FreakingOUT
  19. Had to take a break from this to study for a license renewal exam yesterday afternoon. Fortunately, I passed {SIGH}. Now if I can just get "passed" (PUN) my mental block with this PHP/MySQL matter, life will be roses. Well, almost. Barand had originally pointed out: That fly in the ointment has been resolved for the basic db query to read data already in the MySQL Table, however tied into the PHP script to read the data, is another scrip that first must parse a weird formatted data file prior to INSERTING the data into the MySQL Table (for my initial test I did it manually with phpMyAdmin. I found a custom PHP Class that parses the weird .adi file data OK, except that the first field in the file key value for the array is that same word again: "CALL" ;-( Fortunately, this section of the display code outputs the contents of "CALL" in the browser OK: <?php // Basic schema to Parse an ADIF (.adi) file into manageable data for input to MySQL qsolog Table include 'adif_parser.php'; $p = new ADIF_Parser; $p->load_from_file("test.adi"); $p->initialize(); while($record = $p->get_record()) { if(count($record) == 0) { break; }; echo $record["call"]."<br>"; }; ?> I've tried all sorts of variations of backticks (real ones this time), single & double-quotes, but still can't seem to find the Magic Silver Bullet for adding the "INSERT INTO" (i snipped out all the MySQLconnection stuff) and without getting syntax errors: <snip> $sql = "INSERT INTO `qsolog` (`call`) VALUES (`$record["call"]`); mysqli_query($con,$sql); <snip> Since there will be 8 total fields of data involved, I'd like to try an shorten all the VALUES involved to ones like: '$call', etc. for the $sql line and axe using the longer '$record[ ]' part. Trying: $call == '$record["call"]'; and other variation attempts haven't worked either. {SIGH}. -FreakingOUT
  20. Thank you, mac_gyver. Will have to check with my ISP about the magic_quotes_gpc setting, but it's 3:55AM (local) right now so will have to do this after they open. Only 2 hours of sleep here, so I'm going back to bed {SIGH}. The form entries will never contain a backslash - ONLY A-Z and 0-9 with perhaps an occassional "/" (forward slash) in the 'CALL'. I'll re-read and chew on your info again after I get more SLEEP. -FreakingOUT
  21. I went back and reviewed Barand's comment "Check data has been posted before attempting to query and output the table". Not sure if I understand this correctly, but decided to try and eliminate the premature "No records found" by putting the <form> part at the top of the page. Ran the code through a code checker which showed no errors, but when the page first loads (without doing anything else), I now get this: ?> No records found The latest attempt is below. -FreakingOUT <?php ?> <html> <head><title></title> </head> <body> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> CALL: <input type="text" name="call"> <input type="submit"> </form> </body> </html> ?> <?php // define variables and set to empty values $call = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $call = test_input($_POST["call"]); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } require '/myserverpath/kqr_mysqli.php'; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $call = mysqli_real_escape_string($con,$call); $sql = "SELECT * FROM qsolog WHERE `call` = '$call' "; $result = mysqli_query($con,$sql); if (!$result) echo mysqli_error($con); if (mysqli_num_rows($result) == 0 ): echo "No records found<br>"; else: if (mysqli_num_rows($result) >= 1 ): echo "<div style ='font:11px Arial,tahoma,sans-serif;color:#ff0000'>"; echo "<table border='1' cellpadding='3' cellspacing='3'> <tr> <th>CALL</th> <th>DATE</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['call'] . "</td>"; echo "<td>" . $row['qsodate'] . "</td>"; } endif; echo "</table>"; echo "</div>"; endif; mysqli_close($con); ?>
  22. "DANGER, DANGER, WILL ROBINSON" ... tried your Sanitize function change, but now it yields an error, so am going back to what worked !!! -FreakingOUT
×
×
  • 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.