-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Good typists are not concerned with (extra) keystrokes. I used to type faster than my secretary
-
In this page of the PHP manual there is ample evidence of parms referenced without the colon. https://www.php.net/manual/en/pdostatement.execute.php Doesn't that make this choice documented?
-
Copy client information from one database to another
ginerjm replied to wongle's topic in PHP Coding Help
Perhaps you should describe the real-life situation here that makes you ask this question. If you have two users who are looking at the same data I have to wonder why you want to duplicate this data rather than adjust your app to properly manage it. -
Oh, definitely got errors but perhaps we are showing him/her some better coding style with corrections to boot! I really hate whoever first thought it was a good idea to use php tags inside of some html code. Such a confusing way to put elements together instead of staying in php. People have got to hate that when they first start using it but they continue on because they don't know of an easier way at this early stage of their programmer development....
-
Try this. I had to reformat since I couldn't make sense out of it. //Checking if submit button is clicked if (isset($_POST['submit'])) { //database cn $db = new PDO("mysql:host=localhost;dbname=centrify","root",""); $username = $_POST['user']; $stmt = $db->prepare("SELECT * FROM agencies_data WHERE agency_user ='$username'"); $stmt->execute(); echo '<div class="mb-3">'; while($item = $stmt->fetch()) { echo "<input class='form-control' type='text' name='oid' value='{$item['agency_user']}'><br>"; } echo "</div>"; }
-
PDO - Uncaught Error: Call to a member function
ginerjm replied to Adamhumbug's topic in PHP Coding Help
Feeling magnanimous today, here's the function I use to connect: function PDOConnect($l_dbname=NULL, $l_msg=null, $l_options=null) { if ($l_options == null) { // set my default options $l_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_FOUND_ROWS => true, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); } if ($l_dbname == null) $host="mysql:host=localhost;charset=utf8"; else $host="mysql:host=localhost;dbname=$l_dbname;charset=utf8"; $uid = "xxx"; $pswd = "yyy"; try { $pdo = new PDO($host, $uid, $pswd, $l_options); } catch (PDOException $e) { if (strtoupper($l_msg) == "SHOWMSG") echo "Fatal Error<br>Failed to connect to mysql via PDO. PDO Error msg is:<br>".$e->getMessage(); else echo "Fatal Error<br>Possible bad dbname?<br>Failed to connect to database server. Sensitive error msg may be viewed with additional parm to call to PDOConnect(dbname,'showmsg')"; return false; } if (!$pdo) return false; else // all worked - return handle to pdo connection. return $pdo; } This assumes that you will want the assoc array format returned from your queries. You can easily override that in your fetch calls if you need to do something different at that point. Stick this in some 'php' folder outside of your web tree so that only php scripts (and not html/web pages) can see it. Then simply call it ONCE in your script by: $pdo = PDOConnect($dbname); -
OH, i'm sure you will. HTH
-
PDO - Uncaught Error: Call to a member function
ginerjm replied to Adamhumbug's topic in PHP Coding Help
I would also NOT include/require the connection code within a function. That means every time you call it you re do the connection. Not at all necessary. I would put your connection code into a function that returns the pdo handle ($pdo). And when I call that connection function it would be: $pdo = PDOConnect($dbname) Now you have a handle to use throughout your script and inside other function if you pass it to them. I also wrote my connect function to pass in the dbname to make it more universal. -
Here's a good starting point: http://www.fpdf.org/
-
Show a percentage based on values from a table
ginerjm replied to AndyJones's topic in PHP Coding Help
Simply add these 2 lines to the top of your scripts while you are developing them: error_reporting(E_ALL); ini_set('display_errors', '1'); To turn off change the '1' to '0'. -
Ok then. FPDF is very good at producing a document of data/text from a db or any other source. You basically have to have a plan and you build it row by row as if you were working on an x/y grid where (usually) you write out 'cells' across a row. Works very well if you are trying to output a table view of your data but also for a lot of other things. I have used it to produce drawsheets for my handball events if you can envision what that looks like.
-
Are you wanting to create a pdf document or a pdf image of an html page? IMHO the latter is not an easy task with FPDF.
-
Show a percentage based on values from a table
ginerjm replied to AndyJones's topic in PHP Coding Help
The error in my code is the double equal in the whille line. As for Barand's code, just run it and see what it gives you. -
Who said anything about ftp? If I can hack and get to your pdf files folder(s) What makes you think I can't do the same to your databases? I'm a hacker!! I just did some google searches and I don't see a way to bypass the user having to type in a password to read a protected pdf file without using some other utility to either unlock the pdf or decrypt it and read it. Sounds like Adobe was way ahead of its time. I think you need to rethink your plan here. Nuff said. Good luck. Good bye
-
What does mPDF have to offer you? Obviously we can't help you here (PHP world) unless you find out what access path mPDF can provide. And BTW - you said that you have the pdf passwords stored in a database. And you have your pdf files stored on your system. If you are concerned about somebody hacking into the files what about that same person hacking into the passwords database?
-
So the user does have to login with a password. Why can't that userid be used to determine what files the user can see and not worry about embedded passwords in the pdf files? As I already proposed, assign pdf files to groups (where you put the passwords now) and create a table that links a user id to multiple records of groups that he/she can access. When a user clicks on a pdf button check that his permissions include that group number and show the file. That's the way I would do it. It's either that or read the documentation on mPDF to see if they have an interface that allows an app to provide the password
-
So how does the user get access to the button that gets clicked? Is there a signin procedure requiring a password of some kind?
-
Are you saying that the password is IN the pdf file, or just in a database? If it is in the pdf file then you need to read up on what mPDF allows you to do, not here.
-
If the pdf was encoded with the password how could your app provide that? Could you not use a password in your app itself so that you have to enter it just to get into the app and have access to the files? You could have multiple passwords to provide access to groups of files. Store the filename in a table with a group code and check if the user has logged in with access to that group and only then show him the file.
-
Usually a user has a pdf reader on their system so attempting to open a simple pdf file should trigger that.
-
Oops --- got a small typo in my sample: Change ":val" to ":val0"
-
English?
-
As for your last post, I do believe my code handles your concerns. Run the sample I gave you and see what it produces and then use that in your code.