-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
OK - the pdo connection logic (mine!) is showing nothing wrong. As for the mainline code - I don't see any problems other than your use of this: inet_aton('$ip') Is the "inet_aton" variable an array? If so you are using the wrong syntax. Indices need to be wrapped in [] not parens. Tip: Don't bury a query statement inside a function. Assign it to a variable and use that var in the function call. That way if you need to dump the query to debug it you can simply echo it. Here's how I would do it: error_reporting(E_ALL); ini_set('display_errors', '1'); $php_scripts = '../../php/'; require $php_scripts . 'PDO_Connection_Select.php'; require $php_scripts . 'GetUserIpAddr.php'; //******************************* if (!$pdo = PDOConnect("foxclone_data")) { echo "unable to connect"; exit; } $result = mydloader($pdo, $_GET["f"]); if ($result === true) echo "Success"; else echo $result; exit; //*********************************** function mydloader($pdo, $l_filename=NULL) { $ip = GetUserIpAddr(); if(isset($l_filename)) { header('Content-Type: octet-stream'); header("Content-Disposition: attachment; filename={$l_filename}"); header('Pragma: no-cache'); header('Expires: 0'); readfile($l_filename); $ext = pathinfo($l_filename, PATHINFO_EXTENSION); $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))"); $stmt->execute([$ip, $ext]); $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend"); $ref = $test->fetchColumn(); $ref = intval($ref); $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'"); $stmt->execute(); return true; } else { return "No filename provided"; } } Questions Why are you reformatting the 'id' from one table to the other? Makes it hard to later connect/compare them. What is the inet_aton variable? You are not passing to the function so you should be getting an error message I think. I moved the connect call outside of the function and passed the handle as a function parameter. I added a result to the call to your function and eliminated the buried exit. And I moved the function to the bottom instead of the top. That way when one looks at the script they can see right away what is trying to accomplish (which I still don't see) without having to browse thru a lot of code. And I removed all of the excess spaces. No need for them. As well as the extra blank lines. That may have been caused by your editor when you uploaded it to here.
-
I too am happy to see this site come back alive. Twas a surprise and a bit of a let-down with no info forthcoming . Had to make do with another site which was also down at the same time but only for a couple of days. Of course (as I have posted elsewhere) things on PHP forums seem to be at a standstill - traffic is way down. Hopefully once this site finishes with its transition, things will pick up and those of us who like to come and be of some aid to those needing it can continue to get our fix.
-
Using book Learn PHP 8 have an error that is wrong
ginerjm replied to Markus1954's topic in PHP Coding Help
And how does your latest response resolve the issue? I told you how I would write it. But apparently my old-style way of coding that has worked for 40+ years is no longer the preferred way. I do fail to see how your sample does anything to improve security. Perhaps in that (unknown) function there is something about that but what we are trying to solve really has no relation to that. As you write more you may start to see the value in writing code that is easy to read and interpret. The sample you are showing us of the 'new way' of coding is NOT easy to interpret. Fact. So when you have to go back into this script a couple of years from now, are you going to readily remember what it is doing? Good luck with your progress. I"ll step aside now. -
Using book Learn PHP 8 have an error that is wrong
ginerjm replied to Markus1954's topic in PHP Coding Help
So you are telling us that this line: bool $dog_error_message = $lab->set_dog_name('Fred'); is now giving you the message. I thought that was the problem originally. To me - not a version 8 user yet -I wonder why the elongated code. If the call to set_dog_name function is supposed to do something for you and you want to know it it succeeded or not, why don't you just put the call inside an if and do your 'things' from that instead of setting a variable and then checking it. Of course, I am assuming (!) that the function is expected to return a boolean value already (so why the typecast?) so the following code should work very well: if ($lab->set_dog_name('Fred')) echo 'Name update successful<br/>'; else echo 'Name update not successful<br/>'; -
Are you using PDO or MySqlI? The former is the easier one to use. That said - read the manual under PDO to see how a query statement would look and then simply do it. Here is a very brief and simplified spot of code: // (write a function that makes your connection.) $pdo = PDOConnect($dbname); // this function also sets the db name $q = "select fld1, fld2, fld3 from tablename where fld1=:argument1 and fld3=:argument3"; $qst = $pdo->prepare($q); $parms = array('argument1'=>$myvalue, 'argument3'=>$another_arg); if (!$qst->execute($parms)) { // (handle the error and exit?) } //************* //(now process the query results) As you can see this is simpler than the way MySqlI uses binds and results to manage prepared queries. PDO simply asks you to put the needed :parms into the query and then to prepare it. Then you simply set an array with the values for those parms and execute it whenever you are ready to run the query. Note: you only need to make your db connection once in a script unless you are doing something that requires a 2nd connection (??). Call the connection function once to get a handle and then keep using that handle when you need to run any query. Don't put the connect call inside a function that gets called repeatedly. Simply pass the handle to the function as one of its arguments.
-
Using book Learn PHP 8 have an error that is wrong
ginerjm replied to Markus1954's topic in PHP Coding Help
OK - I see your text answers my first question. Now try removing the bool from that line. It appears now that you are trying to make an assignment. Since you don't want to change the type of the var $dog_error_message remove the bool from the statement. You might want to use that somewhere but I don't think you want it here since you are simply trying to copy one value to another variable. Would be silly to do that simply to get a boolean value when you are really trying to get the value returned from that function call, whatever it may be. -
Using book Learn PHP 8 have an error that is wrong
ginerjm replied to Markus1954's topic in PHP Coding Help
What line number was in the message and are you showing us that line??? And what is that 'bool' at the beginning of the line with your var in it? Is that something new to ver 8? Try removing it. -
PHP: Returning and naming specific fields from a CSV in an array
ginerjm replied to Sonva's topic in PHP Coding Help
More - If you know how your csv file is laid out you could do this also: $filename = 'example.csv'; if ($hdl = fopen($filename, 'r')) while(list($a,$b,$c,$d, $e) = fgetcsv($hdl,1000)) echo "$a $d $e<br>"; // simple output of a single line else echo "Could not open file: $filename"; exit(); Note - I only use lowercase names. Makes it less prone to typos down the road. 2nd note - the echo line shows how to only print certain fields from your csv lines. And it does a very simple output. Instead you could begin an html table prior to beginning the while and then insert table rows for each line your read. Then close the table after the while ends. The key to all this is knowing your csv layout and providing fieldnames for each item in a row and then only referencing the ones you want to use. The list() construct works very nicely for this kind of thing. -
PHP: Returning and naming specific fields from a CSV in an array
ginerjm replied to Sonva's topic in PHP Coding Help
Instead of doing your final output as above where you simply dump the entire contents that you read in, why not simply print only the array elements that you want? As barand showed you your read process could only save specific elements of the csv lines you are reading. You could simply do the output right there instead of saving an array and then processing the data a second time. -
I tell FPDF that it is a letter and I space my text down a few lines and center it across the page. Then when I send the pdf to print I reset the paper to an envelope. Works great except for being backwards, ie, the envelope needs to be rotated away from the normal position in a the paper tray. I did try saving the pdf and then using Adobe to print it but for some reason it doesn't hold the same font size and prints at about 8pt size. No idea.
-
With FPDF the page that the final pdf appears on (before printing) has a rotate option but it doesn't change how the printer prints in any way. Weird. I've added a JS alert to my submit button so that when I click on 'Make PDF' I remind the user (me) to rotate the envelopes. At least I won't waste them.
-
I print envelopes all the time for other reasons and my printer has 2 trays with one of them setup and dedicated to envelopes. Having to remember to rotate them for one app's usage is a pia as you might imagine. I"m hoping that someone has seen this problem before.
-
So - where is the code you are using?
-
Have used FPDF many times for normal letter-sized printing but I am now having an issue with a #10 Envelope. While the printer tells you to insert envelopes a certain way and that's what I have done, for some reason FPDF won't print them the way the envelope is oriented but rather prints them upside down. To solve this I would have to remember to turn my envelopes around every time I used this application and I'm trying to avoid that. Has anyone figured out a work-around for this problem?
-
Simple PHP Include Question - I think my host changed something
ginerjm replied to kirkdickinson's topic in PHP Coding Help
Thank you for giving me credit for your solution but MacGyver actually mentioned it before me as I said earlier. HTH though! -
Simple PHP Include Question - I think my host changed something
ginerjm replied to kirkdickinson's topic in PHP Coding Help
Ok - then that was what was pointed out earlier. Good luck. -
Simple PHP Include Question - I think my host changed something
ginerjm replied to kirkdickinson's topic in PHP Coding Help
Ok - index.php is a good thing. So now show us more of your code. Hard to debug something when we aren't seeing it all Unless it is hundreds of lines in which case you have some work to do. Try adding my echo line to the very beginning of any php code in that file and be sure to move the 2 error checking lines up to the start of the php code as well. -
Simple PHP Include Question - I think my host changed something
ginerjm replied to kirkdickinson's topic in PHP Coding Help
When you say 'index file' what do you mean? Are you saying that you are not using any script and letting your system just use the default home page name? What shows in the address bar when you do run it? Does it have a .php extension on it or is it an html extension? When you type in the ?con=xxx what is immediately in front of that? Show us that whole address bar line. -
Simple PHP Include Question - I think my host changed something
ginerjm replied to kirkdickinson's topic in PHP Coding Help
What do you type in the browser's address bar to run this thing? That has the script name. The name of the program you are working on. That is the script name. -
Simple PHP Include Question - I think my host changed something
ginerjm replied to kirkdickinson's topic in PHP Coding Help
Did you make the correction I posted? If you have fixed my code and tried to run it and got back no message and no error message give me the answers to my previous questions about the script name and the opening php tag.