-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Question on converting existing site from mysql_* to PDO
ginerjm replied to maxxd's topic in PHP Coding Help
HTH with my $.02 -
How about the query statement that retrieved the date? Echo that out first to be sure you are getting what you expect. Of course, as pointed out, using MySQL's DATE_FORMAT function would do all this work for you.
-
Question on converting existing site from mysql_* to PDO
ginerjm replied to maxxd's topic in PHP Coding Help
With the amount of re-write you will have to do to switch over to pdo, how can you NOT alter the queries at the same time? You will simply remove the existing values and replace them with the placeholders and then modify the existing 'query()' call to 'execute(array(key=>value,key=>value))'. Of course you have to reference the un-sanitized values but that too should be simple. -
A blank page usually indicates an error or two in your script. Be sure that you have php error checking turned on at the beginning of that script so you'll hopefully see something
-
Question on converting existing site from mysql_* to PDO
ginerjm replied to maxxd's topic in PHP Coding Help
I do believe you will hear from many here that using pdo's quote() is unnecessary. With PDO you have access to prepared queries which are the preferred way of running queries this century. Read up on them and use them whenever you have to include user-supplied input as part of your query. -
Since you have an invalid function call here (rrmdir) I'm guessing that you didn't bother to turn on php error checking. Do So Now. See what other errors you may have. You could also review this and perhaps shorten it up a bit. For example - why do you explode $filename twice? Why do you not assign the path names up front and use them in place of literal paths being used twice?
-
More importantly - you will have a unique page for each visitor? Really? Or is it just a customized page that is basically the same for all with just some php-generated(?) tweaks to make it more personal? Also - does the url have to be unique for each user (implying again 'unique pages for each user' )?
-
Why the @ in front of every poster's name? I dont' get it.
-
I'll try to explain again. Have your home page - or starting page of your appl - set a cookie before outputting the page Simple. Have a link on this page to take the user to the preferences page. Handle it in the current page's script instead of calling the preferences page directly. If the script detects that the preferences link was clicked, have this same script check if your previous cookie exists - if so send a header to redirect you to your preferences page (or however you will handle them). If the cookie does not exist then simply return the user to the same page with a message.
-
If your most recent post is accurate (meaning the actual code you executed and not a re-type) then you are losing the content-type header. Look at your assignment right after that.
-
Read up on MySQL and setup a database and tables in your environment. Then read some tutorials on querying and hwo to implement either MYSQLI or PDO as your db interface (Do Not Use MySQL_* functions). Pretty basic stuff - create a connection from php to sql; select the database to be queried; write/prepare a query; execute the query; check the results of the query (true or false) and then loop thru them to output information. Posting data to the db is pretty similar. Writing the php is something you will have to also read some tutorials on too. There are some very good books out there - check out a decent bookstore or library and spend a few hours reading, starting with the basics. Most importantly - be sure you use good practices. Security against hacking and injection are the most important things to keep an eye on - don't short-change yourself by ignoring these things. Again - read. The php.net manual is an important resource to all php programmers - set up a keyboard link to it and keep it uppermost in your mind as you write and need to lookup things. Link to that and other resources can be found at this site/forum's home page. Do yourself another favor by avoiding like the plague big chunks of code that you find by trolling the net. You will most likely download something that is years behind the times, uses inappropriate code and does not handle security and injection properly. Learn. Write. Then ask for help.
-
1 - DON"T bury functions inside your main line code. Keep them separate. 2 - You're losing your content-type string from the message body.
-
You cannot send a header once ANY information of ANY kind (characters,blanks, empty lines, etc.) has been output. The message is telling you EXACTLY what line of your code is sending something. Stop it.
-
I have never thought about testing - if my cookies don't show up, I default them to blanks and operate with those values. I have to think that setting a test cookie upon startup prior to clicking on the link to open up a preferences selection page would work. If they click to set their preferences, you simply check for the test cookie and if you fail to get it, you direct them to an 'error' page telling them they need cookies. Otherwise you let them set away! Of course if you are going to have a lot of these cookies you might want to think about a db table to contain all the settings.
-
Uploading Image Location to DB and Image File to Directory using PDO?
ginerjm replied to hankmoody's topic in PHP Coding Help
Change your flow to only upload an image file on new records. Let the user upload the image file first. If the upload is received successfully then prompt the user for the info behind it. To ensure that you don't get a lot of images w/out info, create an image record to track the image name and the date is was uploaded and periodically go thru the image table to look for images that are over a certain age and do not have a true info record in the main table. Basically, you will never have to modify the image once you have it, so just worry about the data after you do. -
Or perhaps that you have your default case above most of the other conditions in your switch. The 'default case' should be after all the other possibilities have been checked.
-
Isn't the whole point of going to a forum such as this to be told what to do? Methinks you have it wrong if you don't want to be told everything you are doing wrong. Is that your complete mastery of the English language? Not much better than your PHP I see.
- 10 replies
-
- php
- authentication
-
(and 2 more)
Tagged with:
-
The purpose of functions is to a) reduce the occurrence of repeating the same code in your script/projects and b) separating out a significant piece of code from the main line of your current process to make the overall code easier to read and follow along with. When you identify any 'task' that you wish to compartmentalize in order to streamline the reading of the entire code assigning a complex (or even simple) set of code to a function and then just calling that code fromt the midst of a process makes great sense. If you have a process to accomplish that involves several distinct and separate steps a good design would be clearly break apart these steps in your code and then create a short piece of code that calls the functions to complete the task in order. For example - to process some input vars, do some calculations, look up some db information and return a result you could break it down into functions that do each of those things. The key is to design your functions to use the appropriate input arguments for each and then pass them from your main process. When you recognize a certain set of code that will come into use many times (or even 2-3 times) in a script/project, make that a function with arguments that allow it to be used with versatility whenever you need that to happen. A simple version might be when you need to compare two values and return some answer that is related to them multiple times. A function that took two input args and returned a value would be both versatile and streamlined and useful all over your project. Experienced programmers are always looking for already-written (and tested) code that does what they want. Good programmers have their own library of functions that they have developed and trust to do what they need. For example - I use a function that I include in all of my database-related scripts to make my db connection and to select the database I wish to use. In it I have included my credentials and as an argument I pass the dbname I wish to have selected and it returns a handle to my connection. Of course I store this script/function outside of my web tree for maximum security.
-
Yes - this is a very confusing question. "A Constant value that doesn't change"? What a misnomer - a constant is Exactly that - a constant. To ask for "a constant that doesn't change" is simply idiotic. So - as Cronix says - "What are you really looking for?".
-
Need help creating a simple video file server
ginerjm replied to chrisyroid's topic in PHP Coding Help
How does one give you an example of a database? Let's see - a database is a collection of tables, generally closely related to an application or to a collection of data. It may also contain sets of disjoint data that for one reason or another it makes sense to the designer to lump into a single database. (In a perfect environment (ie, one which you control) this last possibility would be minimized since you would have an unlimited number of databases.) How's that? -
Need help creating a simple video file server
ginerjm replied to chrisyroid's topic in PHP Coding Help
It is better that you read up on using databases and how to organize your data fields into the proper table structures (normalization) and then how to write simple queries and try them out. Really - learning it yourself is always better than being spoon-fed and not having a clue why it works. -
Need help creating a simple video file server
ginerjm replied to chrisyroid's topic in PHP Coding Help
You hate working with sql? Sounds like a problem to me. If you're going to create appls that use data, the ONLY viable way of managing the data going into the apps is to use sql. Get over your phobia and do a little reading and join the 21st century. Just my $.02 -
I have been truly blessed.
-
I truly believe my solution is the simpler one. It is concise and clear to someone who may be new to php and this kind of processing. What's the objection to having a second fetch in the loop? And no, it is not designed to handle 3 column tables or more - it simply works for the problem outlined and works simply.
-
Chocu3r: I don[t know what code you are seeing but I see a loop that fetches one row, moves array values into local vars, begins a table and row and td element and then outputs name, link, author and cover two times and then closes the table. Then it loops and gets the second query result row and repeats. End result - a table for each result row containing two images side by side of the same data. The if statement you refer to does not exist in OP's code. I stand by my original post, which I have used in the past. Here is my version of OP's code: // Display Content echo "<table>"; while ($rows = mysqli_fetch_array($result)) { echo "<tr>"; // output current row WriteResult($rows); // get a second result row and output it if ($rows = mysqli_fetch_array($result)) { WriteResult($rows); } else echo "<td> </td>"; // complete the current row echo "</tr>"; } echo "</table>"; //********************** function WriteResult($rows) { $Name = $rows['Name']; $Author = $rows['Author']; $Cover = $rows['Link to Cover']; $Link = $rows['Link to Profile']; echo "<td>"; echo "<a href='$Link'>$Name</a>"; echo "<br />$Author<br />"; echo "<a href='$Link'><img src='$Cover' /></a>"; echo "</td>"; return; }