Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. I'll let you setup your own module to do the pdo connection. But the rest of your script is easy. $q = "SELECT COUNT * FROM $db_table"; $num = $pdo->query($q); $q = "SELECT quote,author FROM quotes ORDER BY RAND($num) LIMIT 1"; if (!$result = $pdo->query($q)) { echo "Error running query"; exit(); } list($quote, $author) = $pdo-fetch(PDO::FETCH_NUM); echo "$quote<BR><BR>"; echo "<i>{$author</i>";
  2. If you are going to learn a new db interface I strongly suggest going all the way to PDO. Much easier and much better than mysqli for sure. And learn how to use CSS instead of the outdated <font> tag. And learn not to use the closing php tag.
  3. And now I see the bad paren..... And - have learned a new way of evaluating conditions.
  4. If that first line of code was in your new book, I'd stop using that book. That code doesn't work in my php 7. Perhaps it is new for php 8, but I doubt it. It uses an OR construct (||) that is part of an if statement usually, not an ordinary assignment statement.
  5. Never seen this done before. Sorry it had to happen to you Barand. Obviously Leon gets no help from me anymore. Perhaps the moderators can remove this kind of player from the forum?
  6. Also - wouldn't it be better to add the random number after the real filename to make it easier to find the file by its original name?
  7. If you have code to show us then show us the code - not a black image! I think you don't have 'img' as the name on your INPUT tag for the 'file'
  8. And your attached file showed up?
  9. Do you have error checking enabled and are you displaying the messages? Might help if you trapped for an error on the prepare or the execute as well.
  10. Another good reason to avoid using mixed cases in your php code (and html).
  11. Do you know that the file that you attempted to upload actually got to your server/php? Have you tried to do a move_uploaded_file to create a permanent copy that you can look for afterwards and know that your upload was a success? 10 mins later. I notice that you did NOT use move_uploaded_file to save the upload under the name that you later use to make an attachment. That is your problem. If you had use the tmpname then you would have had a file. I suggest that you use the move function to save the uploaded file into a special folder for such attachments and then attach that newly saved file to your email.
  12. PS to my previous - hard to call a file a 'CSV' file if there are no commas in it...
  13. Appreciate the credit Requinix. Hopefully OP will make sense of what we are telling him about 'roots'. OP - one thing that needs stressing. Your statement is something that you should NEVER do. The global array $_SERVER (along with many others) is not for changing. It is for reading only in order to gather info that you are seeking, not to save info that you want to use. On my host my domain was setup by my provider to give me a 'root' of "/home/albany/public_html". If I had wanted to setup all my 'stuff' in a myproject folder then I would append that to my provided root path to give me "/home/albany/public_html/myproject".
  14. Are your files 'code' or just raw data? You are showing arrays in your samples, but raw csv files do not have arrays in them.
  15. Root to the rest of us is a specific term that is related to the domain or the html web root. So I am assuming that your root myprojects folder is under the true html root folder. So if you want your php commands to locate the folder you want you need to probably specify $_SERVER['DOCUMENT_ROOT'] as I mentioned along with the /MyProjects/../...... path to your desired folders. $_SERVER['DOCUMENT_ROOT'] . '/MyProjects' would position in what you are calling root. If you other folders are beneath that then add them to it with a leading backslash of course. Hope this is what you are looking for.
  16. What is that line supposed to be? Don't recognize. As for the php tags. Would you believe that when I write my scripts I use a single php tag in the whole damn thing? No need to keep leaving php and coming back in. Read up on it. And what they are telling you is that when you are NOT in php mode any spaces or blank lines in your script will be treated as blank html lines/code. That is a problem when you try do to php type things a little bit later. My scripts all begin like this: <?php session_start(); php code php code php code .. .. .. $code=<<<heredocs html stuff js stuff css stuff more html stuff heredocs; echo $code exit(); Not even the lack of an ending php tag. Not necessary.
  17. The dots are simply pointing to one folder up from the current loc. If you have a folder MyProject under your root folder then why not specify that one? Use the document root setting in $_SERVER and add MyProjects...... to it. PS - to what are you referring when you say 'root'? The html root or the root of your domain?
  18. An error occurs. Great. Care to tell us what the error is? BTW - if you reference a session var without doing the session_start first OF COURSE you will get an error there.
  19. Or you could just print out the script and scan it in on your printer if that produces pdfs....
  20. What am I not privy to? I see no user of errno nor mysql in this topic. And not much real code either.
  21. You were correct when you said this table was unstructured. Why do they even make it a table when it is just stuff? Maybe you research task should be teaching the provider of this slop some organizational coding.
  22. A research task or just plain "HOMEWORK"? btw - Many of us here do not click on links to nowhere. If you want to show us something post a small example of it right here. Using the proper code tags of course.
  23. To be clear the Barand line should look like if ($_SERVER['REQUEST_METHOD'] == 'POST') { (process post items here } Note that the ] was missing as well as a closing quote
  24. Quite. Perhaps you need to go back to reading up on how to write html? For the heck of it here's a sample of what a form could look like. Note the things that are different from what you produced. // producing an html form from php // this form will produce 3 POST entries: fld1, fld2 and btn $code=<<<heredocs <form method='POST' action='(this script's name)' autocomplete=off> <label>Enter this data item: <input type='text' name='fld1' class='sz_10' value='$fld1'> </label> <br> <label>Enter this data also: <input type='text' name='fld2' class='sz_6' value='$fld2'> </label> <br> <input type='submit' name='btn' value='Submit'> </form> heredocs; echo $code; This utilizes PHP's heredocs verb to produce easy-to-write and easy-to-read html while in php mode. It also references a couple of css classes to help set the size of the input fields. Read up on css and avoid the antiquated use of styles on your input tags. Note the use of label tags. And note the use of var names in the value clauses of the inputs. These can be used to send back the user's input when your script needs to report an error and you don't want the user to have to re-type their inputs when you send the form back to them. A lot to learn which will benefit you immensely if you simply try and follow it. Along with a reference manual.
  25. Because you didn't read Barand's post completely. As well as my comment about where you placed the method and action clauses. Is this your first script using an html form?
×
×
  • 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.