Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Why are you posting in this thread that is 6 months old? Post a new thread.
-
Although requinix's solution should work, this is simpler: $T_Start_Date = "2011-10-23"; $P_Days = "30"; $T_End_Date = date('Y-m-d', strtotime("$T_Start_Date +$P_Days days")); echo $T_End_Date; Output: 2011-11-22
-
OK, if you are going to have a timed-event occur on the server and you want the user's page to show a dynamic countdown to that event, then you should "prime" the JavaScript counter using data from the server. So, determine the GMT offset in the PHP code (i.e. server-side) and then use that to populate the offset as a JavaScript variable. Then use that variable in the JavaScript code to ensure the count-down is being calcualted using the correct time. Then the user's time setting does not impact the timer.
-
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=342417.0
-
If you are not storing the value as an MD5 hash, then why are you converting the values to MD5 hashes to compare in the query? I have to assume the user isn't entering the value as an MD5 hash. So, that means you are converting the user entered value to an MD5 hash and then comparing that to the MD5 hash of the DB value in the query. That's stupid. Why not just compare the user entered value to the DB value without any MD5 conversion? However, the whole point of hashing the value in the DB is so YOU (or anyone else that access the data) will not know the users' passwords!!! You are not supposed to know what their password is. That creates a security risk. People with access to the database could log into the application as one of those users and perform actions posing as that user and, more importantly, since users use the same passwords for multiple systems you could potentially access other applications/sites that those users access. As for "And i don't think that their is something ANTI MD5", I don't know what you mean. But, when storing a password as a hash (which you should absolutely do) you should always do so using a salt. Users with simple passwords could be determined using a rainbow table. And the whole point of hashing the password is to secure the data. As the caretaker of this data you need to take some responsibility in ensuring that the users' sensitive data is not exposed.
-
LOL, why would you store the password in plain text and then when looking for a match you take the user entered value - convert it to a hash and compare it to a hash of the database value? What is the point of using a hash in this instance? You need to store the password as a hash (and use a salt while you are at it.) As to your problem, the query is failing. The query may be wrong, which would result in no matches, but I don't see anything blatant that would cause it to fail. You may have a typo in field names that is causing the failure. Add some error handling to the query to see the error $result=mysql_query($sql) or die(mysql_error());
-
$string = '99,99,28,99,28,112,78,99,28,112,78,28,112,78,112,78,112,'; $string = trim(implode(',', array_unique(explode(',', $string))), ','); Explanation: explode() creates an array with each part separated by a comma as a value (note; there will be an empty value at the end due to the trailing space) array_unique() removes duplicate values from the array implode() Converts the array (of only unique values) back into a string separated by commas trim() removes the trailing comma due to the empty values in the original array
-
From the manual: http://us.php.net/manual/en/function.header.php Also, as I alluded to before, this if() condition serves no purpose: if ((($row['pword']) == $password) && ($row['uname'] == $_SESSION['user'])) { Your query is only pulling records where that condition is true and you are already testing that there was a record (or records returned). This just over-complicates the code.
-
Check the spam folder.
-
Use this code and you should know exactly where the problem is. By the way, you need to implement error handling for any process that could fail, such as the delete query and the rmdir() functions. echo "Records returned: " . mysql_num_rows($result) . "<br>\n"; if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); echo "Results of query " . print_r($result, true) . "<br>\n"; echo "Username compare: DB value = '{$row['uname']}'; Session Value = '{$_SESSION['user']}'<br>\n"; echo "Password compare: DB value = '{$row['pword']}'; password var = '{$password}'<br>\n"; if ((($row['pword']) == $password) && ($row['uname'] == $_SESSION['user'])) { $result = mysql_query("DELETE FROM members WHERE uname = '$_SESSION[user]' AND pword = '$password'"); if(!$result) { echo "unable to perform delete query<br>\n"; } if(!rmdir('users/$_SESSION[user]/uploads')) { echo "Unable to remove upload directory.<br>\n"; if(!rmdir('users/$_SESSION[user]')) { echo "Unable to remove user directory.<br>\n"; //Comment out the redirect for testing //header('Location: logout.php?accountDeleted'); mysql_close($result); } }
-
The first thing that jumps out at me is the first three lines if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); if ((($row['pword']) == $password) && ($row['uname'] == $_SESSION['user'])) { I would assume that the originating query ($result) would be a select statement using the password and username as WHERE conditions. So, why would you need the second if() statement to see if the username and password match the record? If that query isn't using the username/password as conditions then you may be returning more rows than the one for the user you want to delete. And, that code is only processing the first record. Also, I don't see that either of those if() statements have an else condition. So, how do you know if the condition is false? You know, problems like these are very simple to debug. Just add some echo's to your code to validate what is happening. For example, echo the actual value of mysql_num_rows($result) to the page (preferable right before that first line above: echo "Records returned: " . mysql_num_rows($result); If that returns 0 or >1, then you know the problem is likely with that query or the parameters used in it. If the value is 1, then you can "assume" the results are correct and then continue to debug inside the first if() condition.
-
Struggling with creating a new array based on two existing arrays
Psycho replied to galvin's topic in PHP Coding Help
OK, here you go. I substituted the two queries for ONE query that returns the unselected teams. Also, I have reconfigured the logic. I highly recommend you start separating the logic (*i.e. the PHP code) from the presentation (i.e. the HTML). The only PHP code I put in the HTML is echo statements to output the dynamically generated content i build in the PHP logic. There are a lot of benefits to doing this. <?php //Create and run query to get the unselected teams for user $query = "SELECT teamid, teamcity, teamname FROM teams WHERE teamid NOT IN (SELECT teamid FROM picks WHERE userid = {$_SESSION['userid']})"; $result = mysql_query($query, $connection); //Check results if (!$result) { die("Database query failed: " . mysql_error()); } else { //Create select list options of unselected teams $teamOptions = ''; while ($row = mysql_fetch_assoc($result)) { $teamOptions .= "<option value='{$row['teamid']}'>{$row['teamcity']}-{$row['teamname']}</option>\n" } } ?> <form id='pick1' action='submit.php' method='post' /> <table id='submitform'> <tr> <td>High Score Pick:</td> <td> <select name=\"pick1\"/> <option class='default' value=''>Select a team</option> <?php echo $teamOptions; ?> </select> </td> </tr> <tr> <td><input type="submit" name="submit" value="Submit High Score Pick" class="submitpicksbutton" /></td> </tr> </table> </form> -
Well add it so it will show any errors if it fails! mysql_query($query) or die("$query<br>Error: " . mysql_error());
-
Struggling with creating a new array based on two existing arrays
Psycho replied to galvin's topic in PHP Coding Help
I agree that this does look like a query issue NOT an array problem. If you were to show the two queries you are using we could provide a single modified query to get the "unselected" teams as your result. Or, if you need the selected and the non-selected teams we could also provide a query that gets all the teams and provides a value to identified if they are selected in the result. But, to answer the question directly, the array_dif() function is what would do what you are asking about. But, I think that would be the wrong approach. A change in DB queries is the solution. EDIT: the reason you are getting duplicates is due to the mysql_fetch_ function you are using - I'm guessing mysql_fetch_array()?. Again, if you showed some actual code we could help. I would suggest using mysql_fetch_assoc(). -
@BigTime: You should never run queries in loops. It does not scale and your site would crash/hang as you added more data/users. Lear to use joins and process the data correctly. acuken had the right idea with one qury to get all th edata. Then you just use a variable (such as $currentYear above) to identify when there is a change in the data. You just need to ensure you sort the data appropriately beforehand.
-
Here's an attempt at what I think you need. Adding the part to display the year is not a problem, it is fixing the rest of the code that is creating invalid HTML that I guessed at. I changed it to create ONE table to display all the records. Creating separate tables seems odd since the columns will not line up properly. I also revised the query to use JOINs. <?php $sql = "SELECT dates, seq, title, days, times, instructorId, fName, lName, startDate FROM classOfferings JOIN classes ON classOfferings.classId = classes.classId JOIN instructors ON classOfferings.instructorId = instructors.instructorId WHERE classOfferings.startDate >= CURDATE() ORDER BY classOfferings.startDate"; $result = mysql_query($sql); if(!$result) { die('Could not get schedule: ' . mysql_error()); } if(mysql_num_rows($result)==0) { echo "There was no data available."; } else { //There was data, display the results $currentYear = ''; //Var to track changes in year //Open table echo "<div><table>\n"; while($row = mysql_fetch_assoc($result)) { //Determine needed variables $status = ($row['hours'] != 0) ? '' : 'CANCELLED'; $year = date('Y', strtotime($row['startDate'])); //Show year header if changed if($currentYear != $year) { $currentYear = $year; echo "<tr><th colspan='3'>{$currentYear}</th></tr>\n"; } //Display the record echo "<tr>\n"; echo "<td>{$row['dates']}</td>\n"; echo "<td>{$status}</td>\n"; echo "<td class='cell2'>"; echo "<a href='classDetail.php?seq={$row['seq']}'>{$row['title']}</a>"; echo "{$row['days']}{$row['times']}"; echo "<a href='instructorDetail.php?instructorId={$row['instructorId']}'>{$row['fName']} {$row['lName']}</a>"; echo "</td>\n"; echo "<tr>\n"; } //Close table echo "</div></table>\n"; } ?>
-
I'm having a hard time following the logic in your code with respect to how the output is created. For example you start the output with closing </td> tags based on a value from the current record. That means you are closing the previous record with different values based on the next record? Doesn't make sense to me. And each record is closing a tale, but not opening one ? ? ?
-
Something like that. I understand how it works, but I'm not always accurate on the terminology. So, I don't want to state something that could be misinterpreted. Take a look at a PHP Class Tutorial (there is one on this site) to get a more thorough explanation.
-
The reasons for email ending up in spam are many. In the end, you can exhaust every available option, setting, etc. and still have your email flagged as spam. If it were easy to ensure your email didn't end up in spam, all the spammers would do that. With that said, there are some things you can do to reduce the chance of your email being flagged as spam. I am by no means an expert in this, but I have experienced this with an enterprise class application and had to interface with many teams to resolve. There were several issues encountered. Here are some things you can look into: 1. Setting the appropriate headers for the email 2. Avoiding attachments (especially exe) 3. Use an appropriate FROM address. Preferably, the SMTP server you are sending the email from should be the "approved" email server for the domain of that email address. I.e. if you are sending from me@mydomain.com, then the SMTP server should be the approved one to send email for mydomain.com. Some email servers will check incoming email and do a reverse lookup on the from email address and the server that sent the email. Although I doubt this is your problem as I know this isn't the case with gmail 4. Check your content. Make sure it isn't to "brief" and doesn't have all caps, or certain words that may be typical of spam. Also, different email servers use different methods of detecting spam. Part of that process is using "black list" of servers that have been deemed spammers. Even though YOU may not be sending spam another user that uses the same provider as you may have and caused your providers email server to be added to a black list used by one server and not another. This "should be rare as providers do not want their email servers to be black-listed and will kick users that abuse the system.
-
Yes, your user table would have a column for the primary key - which would be set as an auto-increment int field. That way the value will always be unique. So the user table would have some fields such as user_id | username | date_created | password | etc. . . So, the '6' and '10' from my first post would point to the records in the user table with the user_id of '6' and '10'. Also, on second thought, you might also need a unique ID for the messages table in case you need to allow for user to edit/delete the messages. You would need the unique ID to determine the record to update/delete when you run the query. There are tons of tutorials on the net, just do some searching. But, take a look at a few different ones. Although there is lots of good information out there, there is also lost of bad information. I like the tutorials on Tizag which are good for explaining the "how to", but I'm not sure they have anything on the concepts for creating database structure. As for "organizing" the database - you don't - just add the records as they come in. You can SELECT the records you want in any order you want when you need them.
-
Also, why are you running mysql_real_escape_string() on values that you should be validating as numeric or date values? mysql_real_escape_string() is for "string" values as its name implies.
-
Your problem is due to variable scope. A variable defined outside a function and one defined inside a function are two completely different variables (unless you do some certain things to tell the application that they are to be the same). For classes there is an easy solution. You define the "properties" (i.e. variables: $id,$brand,$partnumber,$price,$per) at the top of the class. Then inside your functions if you want to set or access the values for those properties you would do so like this $this->id = 1; So in the method (i.e. function) search you would do the following if($num_rows==1){ while ($row = mysql_fetch_assoc($result)) { $this->id = $row["id"]; $this->brand = $row["brand"]; $this->partnumber = $row["partnumber"]; $this->price = $row["price"]; $this->per = $row["per"]; } You need to do that within any method (function) of the class where you want to set/access the properties (variables) of the class. Although a simpler solution would be to simple have a class property called $data that is an array. Then you could just use $this->data = $row;
-
No it would be more like this user_id_from | user_id_to | message | created | read 10 | 6 | Hi there! | 2011-08-24 10:25:16 | 1 10 | 6 | how are you | 2011-08-24 10:25:46 | 1 6 | 10 | I am fine | 2011-08-24 10:26:33 | 0 You would use a foreign key for the user id that points back to a record in a user table.
-
I'm not really following what you mean by "How can I edit this to 'deal' 12cards (6 & 6) until all the cards are a specific 6 & 6 I pick out?". Are you wanting to run the function over and over until, say, you get one hand with two pair and the other with four of a kind? Sounds, like you are wanting to cheat the game. Anyway, You are over complicating this whle script. For example, to "split" the array into two arrays you use this inefficient looping logic: for($z=0;$z<$arraySize;$z++) { if($z<$cutLocation) array_push($firstArray, $cardsArray[$z]); else array_push($secondArray, $cardsArray[$z]); } When instead you could simply use array_chunk() or array_slice() $firstArray = array_slice($cardsArray, 0, $cutLocation); $secondArray = array_slice($cardsArray, $cutLocation); But, why would you split the deck into two stacls and alternate cards between the two? When you cut a deck you should put the bottom half on top of the deck and deal from the top. Anyway, I'm really not going to try and read your code and give advice on the rest since you don't bother to put in comments for the mojority of the code. It's too laborious a process to try and determine the intent of the code without comments. So, I wouldn't even be able to suggest a solution for what you are asking since I have no clue what is happening where.
-
You will want to create a function that is run "onload" of the page. That function should get the next line of text to display and populate a div with that content (hint, "innerHTML"). Then at the end of the function you would use settimeout() to call the function again (i.e. make it recursive) after 5 seconds.