Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
brown2005, you need to help us out here. You need to be specific and provide clear details. Giving a general response such as that doesn't help to provide clarity. For example, I don't fully understand how you created the three tables and what the association between them are. It appears the "domains" table holds the domains and their info. Then it appears the "words" table holds the actual keywords. So, I will *assume* the "keywords" table records contain a foreign key reference between the domains and words tables. But, I don't know how you "USE" those values and what you expected results are. I would expect that you would want one entry for "rugby" and one for "league". I don't see any need to create a specific association for the concatenated "rugby league". But, since I don't know how you implemented the keyword checks or how "rugby league" would not work with just the single words, I can't provide any guidance.
-
That is impossible to answer without understanding how the data is used.
-
MySQL error when single quote or double quotes are used
Psycho replied to barkly's topic in PHP Coding Help
A few more comments: Your logic is to prevent the insertion of a record with a duplicate "message" content. But, you are doing a "SELECT *". There is no need to select data for this, plus it is inefficient. You could just SELECT COUNT(*) and check that the value is not zero or just select a single field with a LIMIT of 1 and check the count. Both would be better options that SELECT * on all the records. Second, if you really want to prevent duplicates that is a poor approach. A "race condition" could cause duplicates to be created - i.e. when the select is run the duplicate does not exist, but by the time the INSERT is run the duplicate would exist. If you really want to prevent duplicates then set the field as "unique" within the database. This will absolutely prevent duplicates. Then you could just run the INSERT query only. If there is an error from the query you can check if it was due to a duplicate constraint. Lastly, checking for a duplicate on a 'message' value seems a little odd. Are you doing this to prevent an issue with people accidentally double posting? This could be due to a poor design in the actual posting logic allowing people to do a page refresh that was causing the double postings. There are better ways to prevent this, such as doing a redirect right after the post data is processed. -
Why do you have this //include connect.php page for database connection include('connect.php'); The code that appears before this is already connecting to the DB and selecting the DB. If you look at the logic of your page, there are conditions for which there is no handling. For example: if($_SERVER['POST_METHOD'] == 'POST') There is no else condition for this condition, which means if that condition is not true - nothing will happen. What is "POST_METHOD"? There is no such index for the $_SERVER super global. So, unless you defined that variable - it does not exist. I think you meant to use REQUEST_METHOD There is more wrong with this code as well. 1. You use the $_POST values to verify the input data - then use $_REQUEST for the value in the query 2. The code uses mysql_ functions which are deprecated 3. The code is open to SQL injection
-
Try SELECT p.player_id, p.player_first_name, p.player_last_name, v.player_height, v.player_weight FROM players p LEFT JOIN player_vitals v ON p.player_id = v.player_id AND v.vital_id IN (SELECT MAX(vital_id) FROM player_vitals GROUP BY player_id) LEFT JOIN teams c using (team_id) ORDER BY p.player_last_name, p.player_first_name
-
Be careful about putting too much logic to try an interpret correct case for people's names. There are plenty of names that have uppercase letters within the name (as opposed to just the first letter). E.g. "Beverly D'Angelo". And there are valid names that start with a lower case character. Any logic you use is bound to screw up someone's name. Perhaps, you can test each name. if it is all caps or all lower case - then modify it. But, even that won't be perfect.
-
Prevent a space (beginning, middle or end) charater in a string with regex
Psycho replied to terungwa's topic in Regex Help
That looks like an expression to verify the complexity of a password. Why would you not want to allow spaces? Using a passphrase is much better than a password and should be encouraged. -
#1, how do you know that creating the new $db object is not failing? Do you have any error handling? The error you are getting would seem to indicate that $db is not getting created correctly. Try doing this right after line 55 to see if $db is an object or not. If it is FALSE, then it is failing somehow. var_dump($db); #2, That line does not show that $_SESSION['role'] is being defined. This error indicates that you are trying to reference that value but it is not defined. This error indicates that there is no "site_url" defined in the class "config" which you are referencing like this: config::site_url
-
1. Where are you defining $db to be an object prior to that call to the query() method? 2. Where is $_SESSION['role'] defined? And have you included the class "config" and does it have a constant called site_url defined? The first two errors for that are just "Notice" errors and should be suppressed in a production environment, but the last one is a fatal error. That you definitely need to resolve. You shoudl also put an exit() after the header redirect.
-
I would modify the end reading. That way if you need the start/end values in their actual values you will have them $start_reading = 99999945; $end_reading = 10; if($end_reading < $start_reading) { $end_reading += 100000000; } $usage = $end_reading - $start_reading; echo $usage;
-
I really have no clue what you are asking. Your explanation seems to have taken a 180% turn halfway through. I understand what you were talking about with wanting a numerical value that repeats after 99,999,999 (although it probably isn't necessary). Then you go on to an example using 4 as the repeat limit, but the things with the dates doesn't make any sense whatsoever. You discuss using two dates where the difference is used to come up with this number (which was supposedly incrementing up to 4). But, what is the significance of the dates? The dates are going to be whatever they are so, the value is whatever the value is. If the difference between those dates will be incrementing accordingly then it works - else it does not. So, it seems as if the dates used are what need to be 'manipulated'. Um, what? How is the difference between Jan 8 and Jan 11 represented as 3-4=1??? The difference will be three (either negative or positive). In any event, I think you want the modulus operator. With this you can have an infinite "base" number that results in a repeating series with a maximum you define. The modulus is the Remainder from a division. For example, 10 / 4 = 2 with a remainder of 2. So, the modulus is 2. The cool thing is it results in the ability to create a numerical repeating series. The modulus is represented using a percentage symbol - %. Using the limit of 4 as in your above example we can create a repeating series of four - however the numbers will be form 0 to 3. 1 % 4 = (1 / 4) = 1 2 % 4 = (2 / 4) = 2 3 % 4 = (3 / 4) = 3 4 % 4 = (4 / 4) = 0 5 % 4 = (5 / 4) = 1 6 % 4 = (6 / 4) = 2 7 % 4 = (7 / 4) = 3 8 % 4 = (8 / 4) = 0 9 % 4 = (9 / 4) = 1 10 % 4 = (10 / 4) = 2 You could simply add 1 to the modulus result to get the series to be the range of 1 - 4. You could use the modulus on the value before you store it in the DB or can simply let the number stored to the DB be infinite and use the modulus after you retrieve it. You really didn't provide enough information to understand how you are using this to make a good suggestion.
-
How do you know "it is not happening"? There isn't anything in that code that would display anything to do with the records to even know what records were returned. You are just including the same file over and over. Perhaps you are using the value of $row in that include file. Try echoing the results of the query instead of doing the include and post the results. Try this ONE query instead of the looping queries. Also, you shouldn't use "*" in your select statement. List out the actual fields you need. $query = "SELECT * FROM `flags` JOIN `thread` ON thread.id = flags.thread_id ORDER BY thread.id ASC, thread.date_created DESC";
-
You're kidding, right? I'm more than happy to "Help" you. I'm not going to build something for you. Your original post only stated you weren't able to figure out how to create the query for what you needed. And, even though you really didn't provide all the necessary information I made some calculated guesses and provided some examples to point you in the right direction. Now, you come back simply dumping your current code with a statement that you need a new table and a requirement for new functionality to update data based upon some vague requirement. Forget it. I'm out.
-
I believe the refid is the same as the member id from the same table (also not included in the details above). So, let's say the ID for my record is 25. If I then refer JCBones a new record will be created for him. His record will create a new ID (say 52) and the refID will be my ID of 25 since I referred him. rajasekaran1965, do not use '*' in your queries. It is lazy and inefficient. List out the fields you need. And, don't put ID values in quotes in a query. //Get the data of the users referred by the current user $query = "SELECT id, firstname, lastname FROM {$members_table_name} WHERE refid = {$_SESSION['user_id']}"; //Get the data of all the users referred by the selected referrer ID $query = "SELECT id, firstname, lastname FROM {$members_table_name} WHERE refid = {$referrer}"; //Get the data of user who referred the selected referrer $query = "SELECT refid FROM {$members_table_name} WHERE id = {$referrer}";
-
O'm not going to read through all your code. Once a user logs in you need to store something into the session so you know they are logged in as they navigate from page to page. At a minimum, you would store something such as the userID. You can use that to query the database whenever you need additional data about the user. But, you can store any other data about the user into the session when they log in (taking care not to store sensitive information). Then you can get that data directly from the session array rather than having to query the database. But, it looks like you are using a cookie for this. That is completely wrong. Anyone could simply create a cookie and make it seem as if they are logged in! When the user logs in, simply save a session value such as //set authorization cookie //setcookie("auth", "1", time()+60*30, "/", "", 0); //DON'T USE THIS! $session['userid'] = $targetname; //Set user ID to the email sent for login Now, on your pages that check to see if the user is logged in, just check that $session['userid'] has a value. And, you can now use that in the code to determine where to save a file that the user uploads. To be honest, there are a lot of problems in your code, but now is not the right place to go over everything. I understand you are still learning.
- 6 replies
-
- file upload
- file
-
(and 3 more)
Tagged with:
-
Also, since you are only including those files as opposed to having a user load them directly passing actual file names is typically a bad idea. It gives a malicious users information about your application that they could try any use to exploit the system. So, I would suggest giving each file an "label" that you would pass in the URL and use that to reference the file. Plus, you could ditch the error condition. If the user doesn't pass a valid value, just direct them to a default page. $files = array( 'home' => 'index.php', 'contact' => 'contact.php', 'products' => 'dir1/products.php', 'services' => 'dir2/services.php' ); if (isset($_GET['nav'])) { if (isset($files[$_GET['nav']])) { require $files[$_GET['nav']]; } else { require 'error.php'; } } else { require 'links.php'; }
-
Let's back up a second. When a user signs up you need them to provide their email address. You are apparently doing this through a form submission and the code receives the submitted value via $_POST['email']. You then use that to create a folder. OK, great. But, after the user has created their account you should not have to prompt them for their email address in the future. Well, unless you provide a way for them to change it. Since you allow them to "sign up" you should have some sort of login system to know who they are when they are on your site. You should then get their email address where you have stored their account info (would assume a database).
- 6 replies
-
- file upload
- file
-
(and 3 more)
Tagged with:
-
That setup doesn't make sense. Checkboxes are not sent in the post data if they are not checked. So, you need to associate the checkboxes with the text boxes. I would make the text boxes an array using the entry name as the index and then use the entry name as the value for the checkboxes. echo "<form method='POST' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<input type='checkbox' name='hashtag_modify[]' value='{$entry1}' /> Modify\n"; echo "<input type='text' name='hashtag_name[{entry1}]' value='{$value1}' />\n"; echo "<input type='checkbox' name='hashtag_modify[]' value='{$entry2}' />Modify\n"; echo "<input type='text' name='hashtag_name[{$entry2}]' value='{$value2}' />\n"; echo "<input type='checkbox' name='hashtag_modify[]' value='{$entry3}' />Modify\n"; echo "<input type='text' name='hashtag_name[{$entry3}]' value='{$value3}' />\n"; echo "<input type='submit' name='submit' />\n"; echo "</form>\n"; Now, you can determine which textboxes to process using the array of checkbox values. foreach($_POST['hashtag_modify'] as $entry) { echo "<br>Name of entry to be modified: " . $entry; echo "<br>New value for the entry: " . $_POST['hashtag_value'][$entry]; }
-
Seriously? I spent time trying to decipher your code and provide a response all for nothing? And then you provide over 100 lines of code with no comments or explanation on what the different sections are doing expecting me to reverse engineer it. This code seems to suffer from the same problems I already stated above. You are making things more complicated than they should be. Every single one uses an aliased dynamic table. Maybe those are necessary, but based on the first one I reviewed I doubt it. Here's an example of something that just doesn't make sense: where datepart(weekday, trans_date) IN ('1', '2', '3', '4', '5', '6', '7') What is the purpose of this line? Is there a possibility that the weekday would be something other than a number between 1 and 7? Sorry, but I'm not going to take more time out of my day to try and understand what you are doing and try to make sense of it. I wish you luck.
-
Why would it have to be rewritten from scratch? All you need to do is change the code that interact with the DB. It is not that much different from what you already have. Now, I could show you how to write more deprecated code to work around the problem. But, that doesn't make sense. If you don't understand the current problem with the deprecated code, why would you want to invest time into learning more about how to write better deprecated code? You could invest that time into learning how to do it correctly. Did you even read the tutorial I provided above? This is a quick rewrite of some of that code. I didn't test it so there might be a few minor issues //Connect to the DB $dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); // check to see if a duplicate exists $sql = "SELECT StringyChat_message FROM StringyChat WHERE StringyChat_ip=\"$ip\" AND StringyChat_message=\"$msg\" AND StringyChat_time>($post_time - 30 )"; $sth = $dbh->query($sql); //$result = mysql_query($sql); $myrow = $sth->fetch(PDO::FETCH_ASSOC); // Checks if record not matching in db if($myrow['StringyChat_message'] == "") { //Create prepared statement $sql = "INSERT INTO StringyChat (StringyChat_ip, StringyChat_name, StringyChat_message, StringyChat_time) VALUES (:ip, :name, :msg, :post_time)"; $sth = $dbh->prepare($sql); //The data we want to insert $data = array( 'ip' => $ip, 'name' => $name, 'msg' => $msg, 'post_time' => $post_time); //Run the query $result = $sth->execute($data);
-
My apologies, I didn't see you used SUBSTRING_INDEX() - which is probably more efficient than what I provided. Totally different approach to get the same results . Although, either method may not work based upon how he wants to handle sub-domains.
-
Your query is failing and, more importantly, is not secure - you are open to SQL injection. You need to change to mysqli_ or PDO for your DB transactions and use Prepared Statements. That will fix your issue and resolve the SQL Injection problem. I prefer PDO. here is a cursory tutorial that will get you going in the right direction: http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059
-
@Barand, a '1' does not sort before a '.'. You would need to use one of the "shift" characters above the 1 to 0 on the keyboard "!@#$%^&*()". There are others, of course, but those are the ones that I know would work off the top of my head.
-
Huh? Hello exists in all the results, so what do you mean you want "hello" first? I'm guessing (and that's all it is because the question is vague) that you want the "hello.co.uk" to be first because the "hello" is followed by a period. Ok, what about sub-domains when they do and do not exist. E.g.: domain.com domain.aa.com domain.zz.com Do you want the "domain.com" to be first because it doesn't have a sub-domain or should the domain.aa.com be first since it is alphabetically first? Assuming you just want to do the first part and nothing else, I see two options: 1. Use regular expression in the sort logic to determine the sort order using a replacement character for the '.' (period) that will come before the '-' (hyphen). But RegEx is notoriously inefficient. Depening how much data you have and how much this process is used you could have performance issues. Here is an example that sorts on the domain - but does so after replacing the '.' (periods) with an '!' (exclamation point). SELECT domains_url, SUBSTRING(domains_url, 1, 1) AS letter FROM a INNER JOIN domains ON a_domain=domains_id ORDER BY letter ASC, REPLACE(domains_url, '.', '!') ASC 2. A better solution, in my opinion, is to store a new value for your records such as "sort name". Then you can define the business rules and save that second value into the table used only for sorting purposes. For example a title such as "The Adventure" would have a sort name of "Adventure, The"
-
I think you need to first go back and simplify the queries. Just looking at the first query, it looks like it is way overcomplicated. I don't see the need for the aliased SELECT query - or maybe I am missing something. Plus, why do you calculate the dateparts for hour/minute in the aliased query and then calculate them in the outer query? Lastly, WHAT value are you wanting to compare between the two queries? You could likely have ONE query to get the single value. Else, compare the values from the two queries to determine which one you want. After reviewing just the first query, I think it could be simplified to this SELECT TOP 1 cdate, comm_id, meter_multiplier, max(cast(total_full_energy_b AS FLOAT)/1000) * meter_multiplier AS totalUsage, datepart(weekday, cdate) as trans_date_day, datepart(month, cdate) as trans_date_month, datepart(hour, cdate) as trans_date_hour, DATEPART(minute, cdate) as trans_date_minute FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] ON [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id] WHERE comm_id = '$comm_id' AND meter_multiplier is not null AND datepart(weekday, cdate) IN ('1', '7') AND DATEPART(MONTH, cdate) IN ('5','6','7','8','9','10') AND cdate BETWEEN '$base_date $base_start_time' AND '$base_date $base_end_time' GROUP BY comm_id, cdate, meter_multiplier ORDER BY totalUsage DESC