Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
It's difficult to really provide any advise since we do not know what data is returned. What is the size of the data returned for $url_address and $mp3? Why do you need to need to get the data in that manner in the first place? Are you scraping the content of another site (not your own)? You are reading at least four different pages/URLs that I can see. You will have to deal with the latency in doing that and there is little that could be done if you don't have any other means of getting the data you are after. The file_put_contents() shouldn't be more of an issue than the file_get_contents(). However, the line to get the address could be slightly improved, but I highly doubt it is the source of your problem $startPos = strpos($url_address, $before_address) + strlen($before_address); $endPos = strpos($url_address, $after_address); $address = substr($url_address, $startPos, $endPos-$startPos); May need to add or subtract 1 from the last parameter in substr() - I was too lazy to test.
-
You need to take your time and really understand what you are doing. Programming is an exacting science. $qry = "SELECT empid FROM users WHERE empid='{$pwd}'"; $sql = mysql_query($qry); $res = mysql_fetch_array($sql); if($res['pwd'] != 1){ Look at what the query is SELECTing. Then, look at what you are comparing in the if() condition. You are checking the value of $res['pwd'] which was not included in the SELECT statement. So, that index does not exist - thus $res['pwd'] will always be NULL. Further, the condition check makes no sense. Even if you did select 'pwd' wouldn't it always be something other than 1? You should be checking the count of the records returned - not the value of the record that was returned. $query = "SELECT empid FROM users WHERE empid='{$pwd}'"; $result = mysql_query($query); if(!mysql_num_rows($result)) { header("Location: setpass.php?msg=ERROR: you dont have the password...."); } else { //Password matches an employee ID
-
No, you don't need a foreach() for that scenario. The emails should be unique in the database, so you should only get 0 or 1 results. You just need to make a single call to get that one record.
-
Well, the flow of your logic has problems. It is always best to check for errors rather than the lack of errors - otherwise the errors appear at the end of the code separated by the check for them. For example, the "Please enter field" error at the end of the code is based upon the condition at the very beginning. Better to do something like this f(empty($_POST['email'])) { echo 'Please enter field'; } else { //Continue with success condition Also, you have a duplication of error conditions. You do this condition after running the query if($getData->count()) { Which, based on the error is to see if there was a matching record. But, later you do another check if($email == $db_email) { If there was a record in the result set then that means the email matched, so why the second check. Plus, you are comparing the escaped value of $email to the DB return value of $db_email - which would not match if anything was actually escaped. but, I don't know what the function escape() does. You are using the same function on the a value returned from the query for use in the email. Different outputs/usages require different types of escaping. I assume you are using a function you built. Don't. Use the functions that already exist. Plus, you should UPDATE the password before you send the email that it was updated. Ok, so having said all of the above, I am guessing your query is failing. I see that you are not enclosing the email in the query within quotes! Here is a complete rewrite of the code in a more logical flow with some additional error handling - not to mention COMMENTS. Use them! They will help you (and us when you ask for help). <?php $message = ''; //Check if the form was submitted if(isset($_POST['email'])) { //Trim the post value and verify it is not empty $postEmail = trim($_POST['email']); if(empty($postEmail)) { //Email was empty $message = "Please enter email<br>\n"; } else { //Run select query using email $emailSQL = escape($postEmail); $getData = DB::getInstance()->query("SELECT email, full_name FROM users WHERE email='{$emailSQL}'"); //Check if query passed if(!$getData) { //Query failed $message = "Select query failed<br>\n"; } elseif(!$getData->count()) { //No records returned $message = "Email not found<br>\n"; } else { //Record returned, attempt to set temp password $full_name = htmlentities($row->full_name); $email = $row->email; $new_password = substr(md5(rand(999, 999999)), 0, ; $updatePass = DB::getInstance()->query("UPDATE users SET password = {$new_password} WHERE email='{$emailSQL}'"); //Check if query passed if(!$updatePass) { //Query failed $message = "Update query failed<br>\n"; } else { //Send confirmation email $subject = "Password Reset"; $body = "Hello {$full_name},\n\nYour new password is: {$new_password}\n\n-Favecave"; if(!mail($to, $subject, $body)) { $message = "Error sending email.<br>\n"; } else { $message = "An email has been sent with a new temp password.<br>\n"; } } } } } ?> <?php echo $error; ?> <form action="" method="post"> <span>Enter your email address:<span><br> <input type="email" name="email" size="40"><br> <input type="submit" value="Recover"> </form>
-
Well, why don't you tell us what IS happening instead of just stating it doesn't work. You have no debugging code to even help you know what vales are or are not present - which would help. But, there is no input type of 'email' - so that may be your problem. <input type="email" name="email" size="40"><br>
-
Use this $lastWeekPrevMonth = date('m-d-Y', strtotime("last monday", strtotime("$curYear-$curMonth-01")));
-
Secure way of displaying PDF's that is HTML5 friendly.
Psycho replied to drewdan's topic in PHP Coding Help
Or they could simply use the snipping tool that is built into windows to copy the image. The bottom line is that you can take many, many hours to add a bunch of hacks to try and prevent users from "copying" the content. But, what is the result? You can't prevent it to any certainty. Plus, all these measures you might implement will add to the potential for bugs, misalignment of the pages, etc. -
Create the options for each item in list one as an array in javascript. Then determine which array to use based upon the selected item in list one and iterate through the array. Lastly, create a sub-function to actually create the options instead of replicating the code to do so. Working example: http://jsfiddle.net/QFDf8/
-
Shouldn't your January period include the week previous to Jan 6th? Otherwise that week would never show up on any of these reports. To get the last Monday of the previous month, this should work $curYear = date('Y'); $curMonth = date('m'); $secLastFridayThisMonth = date('m-d-Y', strtotime("last friday -1 week", strtotime("$curYear-$curMonth-1 +1 month"))); $lastWeekPrevMonth = date('m-d-Y', strtotime("last monday", strtotime("$curYear-$curMonth +1 month")));
-
im stuck with my code. IF this = that show image code.
Psycho replied to djzman's topic in PHP Coding Help
@CyberRobot, I would suggest not using the name directly in the file as it opens up some security risks. I'd at least run intval() on it to make sure it is safe to use in a file name. @djzman, add some code to VERIFY what is happening $file = 'number.txt'; if (!file_exists($file)) { echo "Could not find {$file}<br>\n"; } else { $fil = fopen('number.txt', r); if(!$fil) { echo "Could not open {$file}<br>\n"; } else { $dat = fread($fil, filesize('number.txt')); if(!$dat) { echo "Could not read from {$file}<br>\n"; } else { echo "The extracted value from {$file} was $dat<br>\n"; echo "<img src='image{$dat}.png' />"; } fclose($fil); } } -
Well, to start, give your table a meaningful name, let's say reservations. That table will include the information specific to the reservation and has a one-to-one correlation such as the date, phone payment etc. Then have another table for passengers. Also, you should not store values such as number of adults, you should calculate those values from the database Example: reservations table res_id | date | group_name | cuise | email | phone 1 2014-02-04 Anderson Bahamas anderson@gmail.com 123-456-7890 2 2014-03-21 Roberston Alaska robertson@gmail.com 213-456-7890 passengers table pass_id | res_id | name | type | email | phone 1 1 David adult 2 1 Terry adult 3 1 Alan adult 4 1 Michael adult 5 1 Jane half 6 1 Julie adult 7 1 Alex free 8 1 Joseph free 9 1 Chris half 10 1 Louis half 11 1 Randy adult 12 1 Wendy free
-
Well, you're not checking for errors on the query, so you really don't know if there were errors or not. You're only checking for errors on the DB connection. Also, I don't know what you mean by "adding fields". Are you talking about adding fields to the DB schema or are you talking about adding fields to the INSERT query (which already exist in the table)? Run this and if there is an error you will see the query and the error: $query = "INSERT INTO final VALUES ('$date', '$group_name', '$cruise', '$no_adults', '$no_half', '$no_free', '$email', '$phone', '$accommodation','$payment', '$info', '$name_adult', '$name_adult_2', '$name_adult_3', '$name_adult_4', '$name_adult_5', '$name_adult_6', '$name_adult_7', '$name_adult_8', '$name_adult_9', '$name_adult_10', '$name_adult_11', '$name_adult_12', '$name_adult_13', '$name_adult_14', '$name_adult_15', '$name_half', '$name_half_2', '$name_half_3', '$name_half_4', '$name_half_5', '$name_half_6', '$name_half_7', '$name_half_8', '$name_half_9', '$name_half_10', '$name_half_12', '$name_half_13', '$name_half_14', '$name_half_15', '$name_free', '$name_free_2', '$name_free_3', '$name_free_4', '$name_free_5', '$name_free_6', '$name_free_7', '$name_free_8', '$name_free_9', '$name_free_10', '$name_free_11', '$name_free_12', '$name_free_13', '$name_free_14', '$name_free_15', '$email_2', '$email_3', '$email_4', '$phone_2', '$phone_3', '$phone_4')"; mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error()); But, yeah, you need to normalize your database. Specifically you should not have $name_adult, $name_adult2, $name_adult3, etc. You should instead have separate tables for the values where you will have "multiples" and have individual records with a foreign key reference back to the parent records.
-
So you decided not to fix the problem and use a band-aid. Good for you. Just don't go asking for my help when you need to use some other DATE functions on that field in the future.
-
I am not going to rewrite your script (which is what it is going to take). Your page is a mish-mash of a lot of things that really don't follow a logical flow and it cannot be done with how you have built the page. I only provided the basic logic on how to accomplish what you want. As I said, you already have a bunch of logic to determine what you are going to display. Within that logic you need to define a page title that will be included as part of the output. But, you can't because the page is intermixing the logic (PHP) and the presentation (HTML). You have to output the title at the beginning of the HTML page. But, you output the header of your page before you ever start the logic of what will be displayed on the page. As I stated, you need to run all of your logic before you ever start the output.
- 8 replies
-
- title
- dynamic title
-
(and 2 more)
Tagged with:
-
Hmm, you simply stated you wanted the opposite of the original query. I'm pretty sure what I provided would do that. But, now you state What I really want is all the assets from the current location that don't have a document uploaded that belongs to standard 2 for example That is not the opposite. That part would be the same as your current query. Plus, you state you are wanting "assets" in the result set, but the original query was pulling data from the AssetDocStand table. I think my original query will work with two modifications: 1) Switch the tables so we are starting from the asset table and 2) Make the location condition inclusive. Note I forgot to make the conditions <> in the first one I provided $query = sprintf("SELECT idAssetDocStand FROM Asset LEFT JOIN AssetDocStand ON AssetDocStand.idAsset = Asset.idAsset WHERE (AssetDocStand.idAsset IS NULL OR AssetDocStand.idDocumentStandards <> %s OR AssetDocStand.Archive <> %s) AND Asset.idLocation = %s", GetSQLValueString($colname_DocUp, "int"), GetSQLValueString($colname_Archive, "text"), GetSQLValueString($colname_Location, "int") ); This will include all records from the asset table which: - idLocation Matches the $colname_Location value AND - Do not have any matching records in the AssetDocStand table - OR idDocumentStandards does not match $colname_DocUp - OR Archive does not match $colname_Archive
-
I don't think you can do this with just the query. You can use PHP to determine the dates and then just use a BETWEEN clause. To do this you can use the strtotime() function with relative formats. However, I have found that the results of the relative formats can vary significantly between minor versions of PHP, so you should definitely test the results before using this. Based on the documentation I could have used a simpler solution, but I ended up with the below solutions (someone might find a simpler solution): To get the second to last Friday of the current month $curYear = date('Y'); $curMonth = date('m'); $secLastFridayThisMonth = date('m-d-Y', strtotime("last friday -1 week", strtotime("$curYear-$curMonth-1 +1 month"))); The strtotime() at the end creates a timestamp for the first day of next month to use as a starting point for the other strtotime() which gets the last Friday (which would be the last Friday of this month) and then goes back one week. I've also verified that it works as expected when the first day of the next month is a Friday. However, I'm not 100% clear on what you mean by "PREVIOUS months last week" in order to define the value. Do you meant everything after the last Friday or the second to last Friday? If you can elaborate, I'm sure I can come up with something. Once we can define what that means and come up with a beginning date for the period you can run a query such as this SELECT * FROM TABLE WHERE date_added BETWEEN '$lastWeekPrevMonth' AND '$secLastFridayThisMonth'
-
OK, here is your current query in a more readable format SELECT idAssetDocStand FROM AssetDocStand INNER JOIN Asset ON AssetDocStand.idAsset = Asset.idAsset WHERE AssetDocStand.idDocumentStandards = %s AND AssetDocStand.Archive = %s AND Asset.idLocation = %s So, let's think about what records would get included. The WHERE clause is pretty easy. Only the records that match all three of those conditions would be included. So, in the new query you want to have the same three conditions checking where the records do not equal those values and you want to use OR clauses (i.e. field1 <> value1 OR field2 <> field2 OR field3 <> value3). But, there's another facet to consider - the JOIN clause. That JOIN clause would initially filter out any records where the JOIN condition does not exist. So, we want to also ensure that we get the records that were excluded from the JOIN. You might think that we could do the reverse of that JOIN to get the ones that o not match the condition - but that would also exclude records that were part of the original JOIN but excluded because of the WHERE conditions - and you want those. So, I would do a LEFT JOIN using the same condition as before. Then add a new condition to the WHERE clauses to include records where the JOINed values were NULL. Try this $query = sprintf("SELECT idAssetDocStand FROM AssetDocStand LEFT JOIN Asset ON AssetDocStand.idAsset = Asset.idAsset WHERE Asset.idAsset IS NULL OR AssetDocStand.idDocumentStandards = %s OR AssetDocStand.Archive = %s OR Asset.idLocation = %s", GetSQLValueString($colname_DocUp, "int"), GetSQLValueString($colname_Archive, "text"), GetSQLValueString($colname_Location, "int") );
-
Yes, I understood that. And the answer I gave will solve your problem. You must have logic in the index.php page to determine what content to show, correct? In that logic include code to determine what the title should be and output that. I don't know how else to explain it. I've also provided mock code to help you understand as well. Good luck.
- 8 replies
-
- title
- dynamic title
-
(and 2 more)
Tagged with:
-
I thought that I was pretty obvious. Run all your logic FIRST to determine what page you are on and what you want the title to be. THEN output the page using the title that you defined in the logic run previously <?php switch($page) { case 'page1': $title = "This is the title for page 1"; break; case 'page2': $title = "This is the title for page 2"; break; case 'page3': $title = "This is the title for page 3"; break; } ?> <html> <head> <title><?php echo $title; ?></title> <head> <body>
- 8 replies
-
- title
- dynamic title
-
(and 2 more)
Tagged with:
-
As I said, I have no clue what you are currently storing in that field. I only made an assumption that you may be using a PHP timestamp. I ran a quick test where one INT column contained PHP timestamp values such as '1395254736'. Then I ran a query just like the one above to populate another column that was a date type and I got the expected results. Here is what I had before I ran the UPDATE query post_created | post_created_temp --------------------------------- 1388601010 NULL 1359830410 NULL 1331232610 NULL 1395254736 NULL 1297109410 NULL I then ran this query UPDATE test_table SET post_created_temp = FROM_UNIXTIME(post_created) The results after running that query were post_created | post_created_temp --------------------------------- 1388601010 2014-01-01 12:30:10 1359830410 2013-02-02 12:40:10 1331232610 2012-03-08 12:50:10 1395254736 2014-03-19 13:45:36 1297109410 2011-02-07 14:10:10 Those are the correct date/times that I used to create the numerical timestamps.
-
What is happening? Are you getting any errors?
-
I would add a new field (e.g. post_created_temp) then run a query to populate the new field with appropriate dates. Finally, remove the original field and rename the new one to "post_created". That will cover the transition process, but you'll also need to modify any operations that currently read/write to/from that field to use the correct date format. I don't know what you are storing in that field currently to say how you can populate the value for the new field. But, if you are using a PHP Timestamp you can run a single query to populate the new field. Example UPDATE fusion38t7q_mediapost SET post_created_temp = FROM_UNIXTIME(post_created)
-
I'm not surprised. As I already stated you should store your date values as date types. Part of my solution requires that you fix your database.
-
I am not going to read through all of that code. But, to do what you want you should: Run all the "logic" of your code first and determine what the output should be - THEN create the output. As part of this process you can determine what the appropriate title should be. Do, not intermix logic within the output like this: <div id="status"> <?php if($active == true) { echo "Your account is active"; } else { echo "Your account is not active"; } ?> </div> Instead, run the logic before you ever start the HTML output. Store the output in various variables and include those in the output. <?php if($active == true) { $activeText = "Your account is active"; } else { $activeText = "Your account is not active"; } ?> <html> . . . <div id="status"><?php echo $activeText; ?></div>
- 8 replies
-
- title
- dynamic title
-
(and 2 more)
Tagged with:
-
I've already provided a solution which you don't want to implement. Good luck.