DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
What is the layout of the gangevents table. Is the first column an INTEGER AUTO_INCREMENT column? If so, I think you have to specify NULL not an empty string. OR list the column names and don't provide any value for the auto_increment: INSERT INTO gangevents (GangID, EventDateTime, EventDescription) VALUES ({$gangdata['gangID']}, unix_timestamp(), \"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> donated \${$_POST['money']} and/or {$_POST['crystals']} crystals to the Gang.\") Usually a query error shows some part of the query starting near where the server thinks the error is. In the message you posted that would appear between the single quotes near '' at line 1. I don't remember ever seeing this empty (well maybe once or twice). Also, since your query (and possibly the error message) has some HTML markup in it, when you get the error, you may want to use the "View Source" capability of the browser, find the error, and see what else is being sent to the browser that is being interpreted instead of being displayed.
-
Well what is it doing? Are there any error messages? Is it outputting anything? I'm not sure I understand the question. There were two queries, but we combined them into a single query. Other than the first query to get the requested zipcode's lat and long, there is only one query in this code, and it should return the data you were trying to get with the two queries in the original post. The code in this post looks like it should work. The query in your LAST post will NOT work. It is not the same as the query in the post BEFORE that, which should work.
-
Cool glad to help! And thanks for marking it solved. That helps the next guy. Dates are a pain. Every environment handles them different. In unix (and therefore) PHP they are integers, in mySql they look like strings but are always displayed in a strict format and you HAVE TO insert/update/query them in that format. Some functions apply your TimeZone and some apply the server's timezone, and some just ignore you (they're called blind-dates -- Just Kidding). When you start working with dates in a particular page pick one or the other (PHP's or mySql's) and be consistent. Unix dates are easy to work with, because they are integers. But watch out, day 1 is defined as Jan 1 1970 (or is that Day Zero?). So, you can't event show my birthday in PHP (well, I think PHP 5 now supports negative dates). ... Ok, I'll stop ranting now. I need a drink.
-
I don't know. But if your server provided has the URL file-access disabled, then you will probably have to use cURL (if that is enabled). I have never used it, in fact, never even looked at it, so maybe someone else can offer an idea. Sorry,
-
Yes, to use the multiple checkboxes and one delete button, they ALL have to be in the same form. You will probably want to display the filename as well so the user knows which checkbox to check echo'<form method="post" action="deleteImage.php" enctype="multipart/form-data">'; echo'<ul>'; foreach($files as $file) { echo '<li>Image: ' . htmlentities($file) . '<br/> <Input type=checkbox name="chkFiles[]" value="' . $file . '"/> </li>'; // You may have to use urlencode($file) here, I'm not real sure } echo'</ul>'."\r\n"; // add the submit button here <input type="submit" name="submit" value="Delete Checked"/> echo'</form>'; Now you should have an array of $_POST['chkFiles'][] containing filenames. Going back to your original code with a couple of changes: <?php $path="images/gallery/slideshow/"; //path of images // $image = $_POST['imagefile']; foreach ($_POST['chkFiles'] as $image) { $file = $path . $image; // you may have to use urldecode here (especially if you had to use urlencode in the other) // $file = $path . urldecode($image); if(file_exists($file)) { if(unlink($file)) { echo "The file <i>".$file."</i> has been deleted."; } else { echo "The file <i>".$file."</i> could not be deleted."; } } else { echo "The file <i>".$file."</i> could not be found."; } } ?> I have NOT tested this code, but I think it is mostly correct. You may want to stick some checks in there to see if you actually get any checked boxes before the loop. During testing, add error_reporting(E_ALL); to the top of all scripts so you can see any messages you get.
-
I guess I should have asked: What is actually in $strtdate? You say it is a column in the database, what is the data type of the column? If it is a mySql DateTime, then it needs to be converted to a unix timestamp. You can do that in the original query using "SELECT UNIX_TIMESTAMP(date_column_name_here) ..." or use strtotime() in PHP. Then the $DOW code should work. Note: 'D' in there returns the three character abbreviation, for the long name use 'l' (that's a lower-case L) To increment a unix timestamp add one-day's worth of seconds ( 24 * 60 * 60 ) $newdate = strtotime($strtdate); for ($i=1; $i < 29; $i++) { echo '<td>'.$i.'</td>'; // Oh yeah, now it's an integer, so we want for format it echo '<td>'. date('m/d/Y', $newdate) .'</td>'; //echo '<td>'.$days[$b++].'</td>'; echo '<td>'. date('D', $newdate) . '</td>'; echo '</tr>'; $newdate += (24 * 60 * 60); }
-
That would seem to indicate that you are echoing the resource returned by a query, you have to use that resource to fetch the data: Something along these lines (this is NOT real code, it WILL NOT run): $DBconn = mysql_connect (Host, User, Password) mysql_select_db (Database) $Res = mysql_query(SELECT some stuff FROM somewhere WHERE i want it) while ($Data = mysql_fetch_array($Res)) { print_r($Data) }
-
You need to re-think your logic. 1) if there is more than one file in the directory, you will have multiple INPUT's named "imagefile" and multiple INPUT's named "submit". The way it is written, you have NO WAY to tell WHICH button was clicked or which file you should delete. 2) INPUT TYPE=IMAGE is basically a submit button with your own image on it. So it should not (IMHO) get POSTed unless you actually click on it, although some browsers may POST it whether you click it or not. If it is getting posted, then all of them are getting posted (see #1 above) and PHP is just getting the last one sent by the browser (whichever that is). But there is no VALUE attribute, so I guess it is coming to PHP as an empty value. (Use print_r($_POST) to see what you are actually getting). Your delete script is picking up an empty value from $_POST['imagefile']. The file_exists() function returns true because $file only contains the directory name and the directory exists (a directory is just a special type of file), and so your script is trying to unlink() the directory. The easiest way to make this code work, would be to make each list entry a separate form, and add a hidden field to it that contains the filename you want to delete. I don't know how many files are in your directory, and I don't know if there is any real world limit on the number of forms on a page (I would guess that some browser will choke at some point). I'm not sure of any other way to do this using a separate button for each file. But, you might be able to use a checkbox for each file, setting the name to an array and the value to the filename; then have a single delete button at the end of the form. <INPUT type="checkbox" name="chkFiles[]" value="$file"> You will end up with an array $_POST['chkFiles'][#] = filename_to_be_deleted which you can walk through and delete each file. You may have to urlencode() and urldecode() the filenames, maybe?
-
Did you read the error messages? The PHP configuration on your server does not allow URL access for this (and several other file) functions.
-
Assign $strtdate to $newdate BEFORE the loop. Inside the loop: Use the PHP date function to get the day of the week: $DOW = date('D', $newdate); Increment $newdate by 1 day
-
SELECT CONCAT(topic, sentence) FROM table1, table2 done!
-
That looks pretty close. Just a couple of points: 1) You have the "elseif(mysql_num_rows($rs) == 0){" in there twice. Once before the code you commented out and once after. You might want to fix that. 2) You are creating a table for each record, you should move the table tags outside the loop: }else{ echo "<table>"; while($query = mysql_fetch_array($rs)) { $zipcode = $query[zipcode]; $description = $query[description]; echo "<tr> <td>Zip Code:</td><td>$row[zipcode]</td><td>Description:</td><td>$description</td> </tr>"; } echo "</table>'; } or something like that. One thing I should have mentioned before; performance will (most likely) be better if you can put an index on the zipcode column in the auctions table, and it would (probably) help if you could put an index on latitude and/or longitude in the zipcodes table (actually, only one of those would be used, but I would probably create both unless space is an issue). As GingerRobot said, The "A" and "Z" in the query are aliases for the tables in the FROM clause. Since both tables have a column named zipcode, we have to indicate which table we are referring to when we mention that column in the query. We could just write: jos_bid_auctions.zipcode = zipcodes.zipcode. But thats a lot of typing. So, when we add the tables to the FROM clause we give them an alias" "FROM jos_bid_auctions AS A JOIN zipcodes AS Z". I left the "AS" word out because it is optional and I'm lazy. I choose A (for the auctions table) to make it easier to read, every time you see A. you think Auctions; and I choose Z (for the zipcodes table); see, the letters match up so it's easy to remember which is which. I could just as easily have said: "FROM jos_bid_auctions AS Dog JOIN zipcodes AS Cat", but that would confuse me when I see "AND Cat.zipcode = 12345" which table is that, again?
-
You should be able to do it in a single query with something like this: SELECT A.description, A.zipcode, Z.city, Z.state FROM jos_bid_auctions A JOIN zipcodes Z ON A.zipcode = Z.zipcode WHERE A.description like '%$description%' AND Z.latitude BETWEEN $latN AND $latS AND Z.longitude BETWEEN $lonE AND $lonW AND Z.latitude != $lat1 AND Z.longitude != $lon1 ORDER BY Z.state, Z.city, Z.zipcode I'm not sure why you have the last AND phrase in there, wouldn't that tend to exclude anything in the search zipcode?
-
Check the values of $uuid and $selected before the query is executed. Check your database using those values and look at the dates (select *). Is there actually data there that should be counted?
-
I don't think you can use the '&' in a WHERE clause, change that to AND: $visitquery = mysql_query("SELECT COUNT(*) FROM visitors WHERE ownerkey = '$uuid' AND region = '$selected' AND `date` < DATE_ADD(CURDATE(), INTERVAL +7 DAY)", $connect); By the way, shouldn't that be "date > CURDATE - 7" ? I mean if you are looking for the number of visits in the past seven days. Your query specifies all dates less than NEXT WEEK; that would probably be all of them.
-
I don't know any way to do it in a single sql statement. However, you could build a new table without the duplicate data, drop the old table and rename the new table. I would suggest that you add a unique index on the new table so you don't have this problem again in the future. CREATE TABLE TestDelNew LIKE TestDel; INSERT INTO TestDelNew SELECT DISTINCT * FROM TestDel; RENAME TABLE TestDel TO TestDelOld, TestDelNew TO TestDel; DROP TABLE TestDelOld;
-
Session variables are stored as an array: $q = "SELECT user, message, senttime " . "FROM " . TBL_AUCTION_RESPONSES . " WHERE user=" . $_SESSION['username'] . " ORDER BY senttime DESC";
-
Put "error_reporting(E_ALL);" at the beginning of all of your scripts. You may have errors that are not being reported. If you get errors, post those and we can be more helpful. Here are a couple of issues with that code. I do not think any of these is causing the problem, but without the error messages, there's not much more we can say. You are connecting to the database all over the place. Do it only one, at the top of the script, before you even test if posting is allowed. You only need one connection. You do not need that while loop for users. You should be getting only one user back, right? If you get more than one, you will be posting the message more than once. Your HTML does not look right. You have no HEAD or BODY statements. TITLE belongs in the HEAD, so does the style sheet (I think) but the rest should be in the BODY (why is the STYLE sheet CENTERed?): <HTML> <HEAD> <TITLE>My Name</TITLE> ... other HEAD stuff here too <STYLE>...</STYLE> </HEAD> <BODY> ... a while bunch of stuff here ... </BODY> </HTML> Clean up the code a little, run it with error checking and post the results. Also, when you get a blank page, use the "View Source" capability of your browser. That will show you what the PHP script actually sent to the browser which may have an indication of why you don't see anything. Above all else, be patient! This is not the FREEK SQUAD Help Desk . We are responding in our spare time.
-
What is the layout of the table? Is there some other column that is unique or is likely to be unique?
-
You could just use DayOfMonth(`date`) in the SQL to get the day number instead of picking it apart in PHP: SELECT DayOfMonth(`date`) AS CalDay FROM speaking_engagements Note: Are the back-ticks still necessary? I think so, but I'm not sure. You should always avoid using reserved words for column names, table names, database names, etc. It just makes things harder on you when accessing the table.
-
You have to have quotes in the SQL around the values: $sql="INSERT INTO Users (userid, Username, Password, EMail, `Account Type`) VALUES (" . $count . ",'" . $username . "','" . $password . "','" . $_POST['email'] . "','" . $at . "')"; $result = mysql_query($sql , $connection); I know it's hard to see them but I added them in there. echo $sql before executing it to see your query. Also, VERY IMPORTANT, do not send user input directly to the database without sanitizing it first!! Using $_POST['email'] in your query is not a good idea unless you have already done something to prevent SQL injections. At the very least use mysql_real_escape_string($_POST['email']);.
-
[SOLVED] fopen(...txt,'"a+') not creating file and writing to it
DavidAM replied to phpnewbieca's topic in PHP Coding Help
Oops, the ini_set() function is expecting the second argument to be a string, So I guess it should be ini_set("display_errors", "1");. I don't usually use this function because my configuration is setup to always display errors. I DO always put the other function in every script. Without these settings, you don't see errors or warnings, and you end up with code that can become problematic later. -
Nightslyr: I did not see your post when I posted my response, so I was not contrdicting you, I was trying to answer the OP's question: and thought I should provide as much detail as possible. Unless they're returned from the function and assigned to a variable outside of the function's scope. The variable is NOT accessible outside of the function. The value may be returned but it is not the variable. I admit this may seem to be a nit-picky distinction, but the OP seemed to be a beginner and I thought it would be best if he understood the difference. They are not the same variable; a change to one will not affect the other; in fact, the variable inside the function does not even exist after the return. Exactly the point I was making. The value was returned to a global variable so it could be used later. Well, I was answering the OP's question about what the line of code in the second function was referencing. Since the question related back to his original question of what the global statement meant, I was trying to tie the whole thing together. Yes, using global can lead to problems; including difficult to read code, ease of accidentally changing a "global" value by changing a value inside a function, etc. However, I do use them sometimes. I think we all use the "super globals" which are in fact globals. The difference is that their existance is well documented. If globals are consistently named and documented inside of functions and outside, they can be very useful. As a general rule, however, I do prefer to pass these as parameters. Part of the confusion here is beause the variables have the same name. This, too, is bad practice. Use a consistent naming style for variables, varying the style by the scope of the variable. I use different styles for function parameters, internal function variables and global variables (as well as a different style for constants) just to make it easier for me when reading my code.
-
Variables that are used inside of a function are NOT accessible outside of that function. So the $ShopConfig in getShopConfig() is not being used by any other function. However, the values in this variable are returned by the call and placed in a GLOBAL variable which, in this code, is also named $ShopConfig. These are TWO DIFFERENT variables. The function displayAmount() is referring to the global variable $ShopConfig. In fact, that is what the global $ShopConfig; statement does. If that statement was not inside of the function, the function would NOT be able to reference the global variable.