-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
I've seen this code before. Copy it from somewhere? Anyway - what you want to do is no different than what you are doing to build $thumbnail, altho as I recall from before $thumbnail never gets used. PS - a 'form' doesn't do any renaming of your file. PHP code does it. Also - what is your script supposed to do when if finds an invalid extension? According to your code it proceeds along its merry way trying to rename the file and do whatever else you haven't shown us.
-
Help me resolve a wierd problem in a FORM with radio buttons
ginerjm replied to new2you's topic in PHP Coding Help
Sorry - can't follow what you are saying. Too many interruptions between your dialog and your code. -
WAD for me.
-
Funny that you couldn't add a name to the submit button, but at least I do see another element of POST. You said earlier that you ran the code that I posted. If you really did run that verbatim (ie, unchanged) I have nothing to offer you here. I know of no reason that POST should not contain multiple elements in the 'user_rights' array when you check all 3 boxes. Below is the EXACT code that I just ran successfully in its entirety and it works as expected for me. Sorry. <?php session_start(); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); // // if (isset($_POST["btn"]) && $_POST['btn']=='Submit') { echo 'User rights setting:<br>'; echo '<pre>', print_r($_POST['user_rights'],true), '</pre>'; } else { echo '<form method="post">'; echo '<input type="checkbox" name="user_rights[]" value="0"> 0'; echo "<br>"; echo '<input type="checkbox" name="user_rights[]" value="1"> 1'; echo '<br>'; echo '<input type="checkbox" name="user_rights[]" value="2"> 2'; echo '<br><br><input type="submit" name="btn" value="Submit">'; echo '</form>'; } exit(); Good luck!
-
Always the doubter here, so can we see the full code that you ran to get that now? (The code you post with the additions I asked for.) Humor me and add a name= clause to your submit as well. I'd just like to see something else in the POST array.
-
Add this before your test of user_rights: echo '<pre>' , print_r($_POST,true) , '</pre>'; This will show your entire raw POST array. Let's see what you have.
-
This works the same and is easier to type: echo "<td class = '$NewClass'>"; as well as this: echo "<td class='$newclass'>"; The unnecessary use of Caps will end up biting you in the a** one of these days. Yes - JS (and perhaps other code) insists on this in its function names and vars but php doesn't. It you do use Caps tho, you have to stick with them. IMHO - stick to all lower. Funny how php allows flexibility with function names but not with variable names.
-
I think you should learn more and take this output to a real db rather than a csv. Then you have some REAL data that you can then do anything with later on.
-
What's the point of storing uploads into separate dirs.? Are people going to browse these folders? Cause if they are not, then why go to such lengths to organize them into such a fine level of detail? I have to believe that you are also storing attributes of these files (one of them being the upload date) in a db somewhere and you could simply store the location of the file and its name as a pair of these attributes and use that to locate the file when called for.
-
Simply pass the db connection var in as an argument of your methods instead of declaring it globally. That way your class/methods are portable and not locked into only using scripts where the db connection is identified as $pdo. Read up on function arguments/parameters. What is it you 'understand (I am) saying'? I told you you need to include better process handling in your code. Think about it. If you are being given instructions on how to do something yourself and you run into a roadblock, you need to know what to do in that case, correct? So when writing code you need to think like that and ask yourself -what do I want to do if x occurs. Or if y occurs. Or if z occurs. A good programmer covers all the bases and tries to prepare his system to handle every reasonable eventuality. You didn't do that in this example. You just programmed along and didn't consider that anything could not do what you wanted it to do. It's like going to the store for white bread and they don't have any and not being prepared to buy anything in its place.
-
Error condition not triggering correct response
ginerjm replied to mmckimson1's topic in PHP Coding Help
Wow! This is a pretty incomplete section of code! Here it is cleaned up a bit. //default values $formResponse = "How are you really doing? Use this to find out!"; $imgSource = "blue.png"; If ($country == "United States") { //US zip code query $sql = "SELECT location, revParData FROM zipData WHERE zipCode = '$zipCode' LIMIT 1"; mysql_select_db('db'); $retval = mysql_query( $sql, $conn ); if(!$retval ) { $formResponse = "It looks like you entered an invalid zip code. Please try again!"; $imgSource = "yellow.png"; } else { $sql = "SELECT location, revParData FROM zipData WHERE zipCode = '$zipCode' LIMIT 1"; mysql_select_db('db'); $retval = mysql_query( $sql, $conn ); while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { $location = $row['location']; $revParData = $row['revParData']; } } So incomplete. As Barand said - no results is not the same as "!$results)". Going thru this code I see that you check to see if you are in the US and you do a query for a single zip code record. Incorrectly you then output the 'invalid code' message if the query fails. Skipping that you then re-run the exact same query if the query succeeded and once again output what you think is going to be a result. Actually you need to not only check if the query ran (which you do) but also if it returned a result/row (which you don't. Why you run the query twice - who know? Furthermore - if you use the php manual you must have noticed that the MySQL_* functions are deprecated. Use At Your Own Risk. But since you are set in your ways here is how I would re-write it: $formResponse = "How are you really doing? Use this to find out!"; $imgSource = "blue.png"; mysql_select_db('db'); If ($country == "United States") { $sql = "SELECT location, revParData FROM zipData WHERE zipCode = '$zipCode'"; $retval = mysql_query( $sql, $conn ); if(!$retval ) { $formResponse = "Error running query - ".mysql_error(); $imgSource = "yellow.png"; } if ( mysql_num_rows() == 0) { $formResponse = "It looks like you entered an invalid zip code. Please try again!"; $imgSource = "yellow.png"; } else { $row = mysql_fetch_array($retval, MYSQL_ASSOC)) $location = $row['location']; $revParData = $row['revParData']; } ... No dupe query, no dupe select db, proper handling of all results. Now stop using MySQL_* -
Error condition not triggering correct response
ginerjm replied to mmckimson1's topic in PHP Coding Help
Horribly formatted code post. Let me look at it for a bit. -
Personally I think your functions all need some work. Nowhere do you make any provisions for error handling. Sure your pdo may issue an exception that goes to the error log but what does your appl do to handle that? Furthermore - when a query doesn't return a result - how are you prepared to handle that? Add some logic in each function to test for success or failure and to test if you actually have any rows to return. Be sure to modify your calling code to handle whatever results you may then return. Perhaps return false if the query fails or returns no data, or return the fetched data if it does find something. As for the delete - as chocu3r says - return true or false - BUT after you add some logic to check what the delete query actually did. Time to do some reading.
-
Not sure why you wrote all that code. Your error message implied that there was no timezone set but this indicates that there may have been one. Are you in the same script, using the same .ini file for settings?
-
So? When the link is clicked, update the record after delivering it to the client. Your link is going to trigger some code, correct? That code is going to go get the data and deliver it to the clicker, no? So once your code has read the data do an update query of that record to update your count and then finish delivering the data to the client to be read.
-
What am I not saying? You want to get prices from a store? Try and find an interface for one of your chosen stores. That's what I'm saying. If you want to automate this you will need access to a database connection for each of your stores so that you can pull down product data and use it in your application. Without some kind of connection (provided by the store or an intermediary) you would have to manually create a table of products and whatever information you want to retain about those products. Manually - as in entering it yourself and updating the price, location, status whenever they change.
-
As was said - you need to read the manual on how to use 'date_default_timezone_set' and place it at the top of your script. Ideally it would be in your php.ini (configuration file) but apparently it is not. Then you need to add 'session_start()' at the top of each of your scripts. Make it a habit. Of course if you are not using any session vars in that script I guess you could ignore it, but I use it as part of my std. template just to be sure I don't forget it later.
-
Getting the prices from a store or even the product catalog in a format that you can make use of is, as I said, the tricky part. I'm sure you can write an appl to 'do' all this, but getting the raw data to use in it is the hard part. I have actually thought about this myself and didn't pursue it for just that reason.
-
Question regarding ajax login setting a $_COOKIE[] value
ginerjm replied to maxxd's topic in PHP Coding Help
You didn't say you were coding underneath WP. Not nice. You should be posting in the CMS forum. -
You do have the ! character there, yes?
-
Question regarding ajax login setting a $_COOKIE[] value
ginerjm replied to maxxd's topic in PHP Coding Help
Your main script/page will not recognize the cookies your ajax sets until the browser reloads. -
Is this mix of php and mysql translatable into pure MySQL ?
ginerjm replied to roparzhhemon237's topic in PHP Coding Help
acts? What's a 'acts'? -
So what's different in each server? PHP version? Both apache? Both *nix machines? Look for significant diffs such as these, then if all the same, look for some confg setting that's different. (I'm not qualified to help you any further with this kind of problem. I'm sure others are.)
-
The use of (int) means to produce an integer result variable rather than a 'default' variable based upon the incoming contents. Given an input of 'X123' your returned variable/value would be a 'string' type but if you use (int) you would get 0 since it didn't start with any numbers. OTOH if the input is "123x" then you would get a value of 123 if you used (int). Check out this in the manual: http://php.net/manual/en/language.types.string.php#language.types.string.conversion