Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. I don't see anything in your processing code originally posted, that is referencing the file fields you have in the form.
  2. Could be that you are referencing the POST field with the wrong index value. You should do a var_dump($_POST) to verify you are getting all the fields you think you should be getting.
  3. I vote for converting to binary. The presentation display for that is the same for everyone, right?
  4. 1. If ID is an auto-increment field then just leave it out of your insert query 2. Create the query as a string variable first. So, if there is an error you can echo the whole query to the page. The part of the query displayed int he error really doesn't give any valuable information. 3. Format your query so it is easy to "read". Put in line breaks and spacing to give context to the data Having said that I don't see a syntax error that stands out. The last value in the error seems to be an empty string. That may not be what you intended, but I don't think it would cause a syntax error. Try this. $query = "INSERT INTO vanderbilt_adhd_diagnostic (Patient_Name, Date_Recieved, Date_Of_Birth, Age, Grade, Attention_To_Detail, Sustaining_Activites, Listening, Following_Instructions, Organization, Mental_Effort, Loses_Items, Easily_Distracted, Forgetful, Fidgets, Leaves_Seat, Runs_About, Difficulty_Engaging, On_The_Go, Talks_Excessivly, Blurts_Answers, Difficulty_Waiting, Interrupts, Argues, Loses_Temper, Refuses_To_Comply, Deliberately_Annoys, Blames_Others, Touchy, Angry, Spiteful, Bullies, Starts_Fights, Cons_Others, Skips_School, Physically_Cruel, Stolen_Items, Destroys_Property, Uses_Weapons, Cruel_Animals, Arson, Forced_Entry, Stays_Out, Run_Away, Rape, Fearful, Afraid_Of_New_Things, Worthless, Guilty, Lonely, Depressed, Self_Conscious) VALUES ('$Patient_Name', '$Date_Recieved', '$Date_Of_Birth', '$Age', '$Grade', '$Attention_To_Detail', '$Sustaining_Activites', '$Listening', '$Following_Instructions', '$Organization', '$Mental_Effort', '$Loses_Items, '$Easily_Distracted', '$Forgetful', '$Fidgets', '$Leaves_Seat', '$Runs_About', '$Difficulty_Engaging', '$On_The_Go', '$Talks_Excessivly', '$Blurts_Answers', '$Difficulty_Waiting', '$Interrupts', '$Argues', '$Loses_Temper', '$Refuses_To_Comply', '$Deliberately_Annoys', '$Blames_Others', '$Touchy', '$Angry', '$Spiteful', '$Bullies', '$Starts_Fights', '$Cons_Others', '$Skips_School', '$Physically_Cruel', '$Stolen_Items', '$Destroys_Property', '$Uses_Weapons', '$Cruel_Animals', '$Arson', '$Forced_Entry', '$Stays_Out', '$Run_Away', '$Rape', '$Fearful', '$Afraid_Of_New_Things', '$Worthless', '$Guilty', '$Lonely', '$Depressed', '$Self_Conscious')"; $result = mysql_query($query) or die("Query: $query<br>Error: " . mysql_error());
  5. No, you do not. And you absolutely do not need to run multiple queries to update different fields of the same record(s). I've gone through your code and think it can all be accomplished with just three queries - and no loops. As I don't have your DB and really don't know what you are trying to accomplish, this is not tested. There are other problems I did not address either <html> <form action="NAME.PHP" method="post"> Start Time: <input type="text" name="start"><br> End Time: <input type="text" name="end"> Location: <select name="sv_loc"> <option value="jtown">Johnstown</option> <option value="gahanna">Gahanna</option> <option value="canal">Canal</option> </select> <input type="submit" value="Submit"> </form> </html> <?php mysql_connect( 'lDOMAINt' , 'USER' , 'PASSWORD'); if(!mysql_select_db('DATABASE')) { die(mysql_error()); } date_default_timezone_set('America/New_York'); // Set to true to display query and argument info // $debug_data = false; $debug_data = true; $query = "UPDATE TABLE SET In_out = 'in' WHERE calldate between '$_POST[start]' and '$_POST[end]'"; mysql_query($query) or die("First update failed: " . mysql_error()); $query = "UPDATE TABLE SET In_out = 'out', ext_name = src, svc_loc = CASE WHEN src IN (5101, 5102, 5103, 5104, 5105) THEN 'gahanna' WHEN src IN (5201, 5202, 5203, 5204) THEN 'jtown' WHEN src IN (5301, 5302, 5303, 5304, 5305, 5306, 5310) THEN 'canal' END WHERE calldate between '$_POST[start]' and '$_POST[end]' AND src IN (5101, 5102, 5103, 5104, 5105, 5201, 5202, 5203, 5204, 5301, 5302, 5303, 5304, 5305, 5306, 5310)"; mysql_query($query) or die("Second update failed: " . mysql_error()); $query = "UPDATE TABLE SET ext_name = SUBSTR(dstchannel, 5, 4), svc_loc = CASE WHEN FIND_IN_SET('51', SUBSTR(dstchannel, 5, 4)) THEN 'gahanna' WHEN FIND_IN_SET('52', SUBSTR(dstchannel, 5, 4)) THEN 'jtown' WHEN FIND_IN_SET('53', SUBSTR(dstchannel, 5, 4)) THEN 'canal' ELSE svc_loc END WHERE calldate between '$_POST[start]' and '$_POST[end]'"; mysql_query($query) or die("Third update failed: " . mysql_error()); include('Net/SSH2.php'); $ssh = new Net_SSH2('localhost'); if (!$ssh->login('******', '********')) { exit('Login Failed'); } echo $ssh->exec("php /path/to/php/file/file.php $_POST[sv_loc] $_POST[start] $_POST[end]"); ?>
  6. Then, you probably want a sub-query. You could create a sub-query such as this SELECT tutor_id FROM tutors AS t2 JOIN tutor_category_subject AS tcs2 ON tcs2.tutor_id = t2.tutor_id JOIN subjects AS s2 ON s2.subject_id = tcs2.subject_id WHERE s2.subjects LIKE '%$subject%' That will return a list of all the tutor IDs where the tutor has one or more subjects with $subject in the name. Then, just use that sub-query in the WHERE clause to only pull records where the tutor ID is in the list of that sub-query $q = "SELECT tcs.tutor_id AS tid, tcs.category_id AS cid, tcs.subject_id AS sid, GROUP_CONCAT( DISTINCT s.subjects SEPARATOR ', ') AS subjects, t.tutor_name AS tname, t.tutor_code AS tcode, DATE_FORMAT(t.registration_date, '%b %D, %Y') AS date, t.qualification AS qualifi, GROUP_CONCAT( DISTINCT o.option_name SEPARATOR ', ') AS tutor_option, timg.image_name AS img, city_name AS city, d.district_name AS district FROM tutor_category_subject as tcs INNER JOIN subject AS s ON tcs.subject_id = s.subject_id INNER JOIN tutor_option AS toption ON toption.tutor_id = tcs.tutor_id INNER JOIN options AS o ON toption.option_id = o.option_id INNER JOIN tutors AS t ON tcs.tutor_id = t.tutor_id INNER JOIN address ON address.address_id = t.address_id INNER JOIN city ON city.city_id = address.city_id INNER JOIN district AS d ON d.district_id = city.district_id LEFT JOIN tutor_images AS timg ON timg.tutor_id = tcs.tutor_id AND timg.image_type = 'profile' WHERE t.tutor_id (SELECT tutor_id FROM tutors AS t2 INNER JOIN tutor_category_subject AS tcs2 ON tcs2.tutor_id = t2.tutor_id JOIN subjects AS s2 ON s2.subject_id = tcs2.subject_id WHERE s2.subjects LIKE '%$subject%') GROUP BY tcs.tutor_id";
  7. Your statement doesn't make sense. I have an idea of what I *think* you might need: Are you wanting all the subjects for any tutors who have one or more subjects that contain 'business' (or whatever the search value is)? For example if tutor Bob subjects "Basket Weaving", "Business Administration" and "Statistics" you want all three of those records because he has at least one record with 'business' in the name?
  8. None of those variables are arrays. I'm really not sure what you are doing as it looks like the code is simply reading the data from one file and writing it into another. Are you wanting to combine the data from the three files into a single file? If so, are the files structured in such a way that there is a one-to-one correspondence between the data in the three files?
  9. Are you running queries in these loops? If so, STOP. You should run ONE query to get all the data you need then handle the logic in the processing code. It would help to know the exact structure of the database. You state that Are you saying that there is a single field with a delimited list of IDs? If so, that's going to be difficult to impossible to achieve what you want. Hopefully, the records of subordinate records are determined via an associative table or the user table has the ID of their supervisor.
  10. No, put the data into a database. I don't know all the data that exists in those files or how much of the data you need. But, a bigger question is whether you know how to use a database or not. If not, then you need to learn how to do that first - can't really teach it through a forum post. But, assuming you do know how to use a database and are just having a hard time understanding how to put this data into the DB, here's quick explanation. Following the same logic I provided to loop through all the files you would change the processing logic to extract the data you need from each file and run an INSERT into the database. You, of course, need to create the appropriate tables and fields first. But, let's say all you are going to store is the basic information you have above. It might look something like this: //Set path to foilder with json files to import into DB $jsonDir = "path/to/json/files/"; //Get list of json files $jsonFiles = scandir($jsonDir); $insertValues = array(); //Read each file and add insert value to array foreach($jsonFiles as $file) { $fileContents = file_get_contents($file); $data = json_decode($fileContents, true); $insertValues[] = "('{$data[FirstName]}', '{$data[LastName]}', '{$data[Height]}', '{$data[Rating]}', '{$data[Attribute1]}', '{$data[Attribute2]}', '{$data[Attribute3]}', '{$data[Attribute4]}', '{$data[Attribute5]}', '{$data[Attribute6]}')"; } //Create single insert statement to add data to DB $query = "INSERT into players (firstname, surname, height, rating, pace, shooting, passing, dribbling, defending, heading) VALUES " . implode(', ', $insertValues); $result = mysql_query($query) or die(mysql_error());
  11. What is the purpose of this? I'm really not interested in investing my time to help someone accomplish something that, on the face of it, is foolish. If you have a valid reason for doing this I'll be happy to help. Otherwise, I'm not going to assist someone in implementing something that has no value and would be helping to instill poor practices.
  12. Wow, that seems like a huge waste of resources. Have you considered dumping the data into a database? That would be the logical approach. But, to answer your question you would have to loop through each of the files. If all the files are in the same directory it is simple enough - but a huge waste of resources. But, you did not specify "how" the search should work. There are two fields for name in the JSON data. So, the below solution (which would be a waste of resources) may not work as you intend, but could be updated. Here is some sample code to get you started //Set path to foilder with json files $jsonDir = "path/to/json/files/"; $search = isset($_POST['search']) ? strtolower(trim($_POST['search'])) : ''; if(empty($search)) { echo "Enter a search value"; } else { //Create variable to store match (if found) $match = false; //Get list of json files $jsonFiles = scandir($jsonDir); foreach($jsonFiles as $file) { $fileContents = file_get_contents($file); $data = json_decode($fileContents, true); //Search first and last names separately $fnameSearch = strtolower($data['Item'][FirstName]); $lnameSearch = strtolower($data['Item'][LastName]); if(strpos($fnameSearch, $search)!==false || strpos($lnameSearch, $search)!==false) { //match was found, set variable and break foreach loop $match = $data['Item']; break; } } if(!$match) { //No match was found, display error echo "No match found for '$search'"; } else { //Display data from the match echo "First Name: {$match[FirstName]}<br>\n"; echo "Surname: {$match[LastName]}<br>\n"; echo "Height: {$match[Height]}cm<br>\n"; echo "Rating: {$match[Rating]} OVRL<br>\n"; echo "Pace: {$match[Attribute1]}<br>\n"; echo "Shooting: {$match[Attribute2]}<br>\n"; echo "Passing: {$match[Attribute3]}<br>\n"; echo "Dribbling: {$match[Attribute4]}<br>\n"; echo "Defending: {$match[Attribute5]}<br>\n"; echo "Heading: {$match[Attribute6]}<br>\n"; } } Did I mention this would be a waste of resources?
  13. $name = isset($_POST['name']) ? trim($_POST['name']) : ''; That is what is called a ternary operator, which many people do not understand. It is also referred to as shorthand notation for an if/else which isn't completely correct. So, let me write it out another way that would be easier to explain. That line does the exact same thing as this: if isset($_POST['name']) { $name = trim($_POST['name']); } else { $name = ''; } So, it check if $_POST['name'] is set. If so, it sets $name to the trimmed value of that variable. If it is not set, then it sets $name to an empty string. The key here is that you can do an isset() check on an unset variable without triggering the error you were encountering previously.
  14. Change this $name = trim($_POST['name']); To the code I provided
  15. You are trying to referencing an array index that doesn't exist. I assume this is happening when you load the page before you submit the form. That is a warning that should be suppressed in a production environment but is good to have on in a development environment. However, I typically use something such as below for any fields submitted in a form to work around such errors. $name = isset($_POST['name']) ? trim($_POST['name']) : '';
  16. The code you've provided will return all records where the $search value is contained in the ticket_id field. The only reason I can see where all results would be returned is if $search is empty. Since you say that when you enter a value and there is a match that the appropriate records are displayed I assume that you are referencing the correct post value. If you are entering a value and there is no match - then no records would be displayed. So, I believe, either that is not the correct code that you've posted or the results you are getting are not exactly as you've stated them.
  17. You could just run both queries in a single statement. You could also set up a transaction so if one fails the other is either rolled back or not executed. But, I have to ask, for what purpose are you doing this? If you are doing it as a fail-safe or for scalability it makes no sense. It makes no sense as a fail-safe because whatever you do to table 1 you are going to do to table 2. So, if the data gets corrupted it will be corrupted in both. It makes no sense for scalability because the two tables are in the same database. So, you will not gain any benefits for higher scalability. If you want to have a fail safe or increase scalability you need to be looking at having a separate database that is synced up with the primary. However, this is something that is handled in the infrastructure - not the code.
  18. 1. If you are going to use the same error message (which I absolutely agree with) you can greatly simplify the script. Instead of searching for a match on email and then extracting the password to compare, just do a query to find a match on email and the hashed password. That will cut out a lot of logic in your script. However, if you wanted to implement a locking feature (say for entering the wrong password three times in a row) then you would want to do a check only on the username (email address). 2. I don't see any problem in using a negative number for either the email or password. In fact, I can't think of any scenario where using a negative number as a search value in a query would be a security concern.
  19. I see a few problems. The biggest is you should NEVER run queries in loops. 99% of the time there is a more efficient way to achive what you need and in the other 1% of cases you are probably doing something you shouldn't be. So, you have this loop: while ($row = mysql_fetch_assoc($qry)) { $data[] = $row[biblionumber]."\n"; } And after that you have this line $bib=implode("\n",$row[biblionumber]); It makes no sense to try and implode $row[biblionumber] since it will only contain the value from the last record. I think you meant to implode $data. Even so, why are you imploding data to put into a field in the DB? That's typically a very bad design that is going to create problems for you later on. I also see references to fields from the 2nd SELECT query in the INSERT query that are not part of the result set (e.g. 'tipo' vs. 'tipo_fondo'). Anyway, using the bad design, you can insert all the record you want in a single query. (Although I highly encourage you to rethink this design!). I would provide the query, but, really, what I see in the code makes no sense. You are inserting $bib (an imploded list) into several fields. Also, the incrementing $inc doesn't have a purpose. I could create a single query, but the $inc makes it a little difficult that it would take more of my time than I am willing to invest.
  20. Don't be so sure about that. You *can* configure ANY file to be parsed for PHP code - it is a simple server configuration. But, it is not typical for htm/html files to be set to be sent to the PHP parser. @curielou22 unless you are 100% certain that the server you are using has been configured to parse htm/html files for PHP you should definitely save the file with a php extension. Also, check the actual source of the displayed page, if you see PHP code then you know that the page wasn't sent to the php parser. But, looking at that code, it doesn't make sense. Everything is wrapped in one giant echo statement - even the PHP logic. So, none of that PHP code would ever be processed whether or not it was sent to the PHP parser.
  21. That is not how you do an INSERT with a select. Take a look at the manual for that: http://dev.mysql.com...ert-select.html I have no idea why you are inserting a NULL value for the first record - why not just leave that field out of the insert? Also, what is the purpose of putting an ORDER BY on the select that us being used to insert all the records? This might be closer to what you want INSERT INTO `pommo_subscriber_data` (`data_id`, `field_id`, `subscriber_id`, `value`) SELECT NULL, 1, `pommo_subscribers`.`subscriber_id`, 'SamTEST' FROM `pommo_subscribers` WHERE `pommo_subscribers`.`email` = 'samtwilliams23'
  22. Well, I hate to tell you but your "personal experience" must be based upon a problem which you were not aware of. Whatever fixed your code had nothing to do about whether the select tag was echo'd within the PHP code or whether it was directly within HTML code. It very well may have been due to incorrectly echoing it in the wrong place. When usign code to generate other code it can be difficult to keep track of everything. But, I can categorically state that you can output the select tags within the PHP code to achieve the same results. The two blocks of code will result in the same output: <select name='field_name'> <?php $options = array('1' => 'one', '2' => 'two', '3' => 'three'); foreach($options as $id => $value) { echo "<option value='{$id}'>{$value}</option>\n"; } ?> </select> <?php echo "<select name='field_name'>"; $options = array('1' => 'one', '2' => 'two', '3' => 'three'); foreach($options as $id => $value) { echo "<option value='{$id}'>{$value}</option>\n"; } echo "</select>"; ?>
  23. Why not just store the IDs as values instead of making then indexes and creating a more complicated mufti-dimensional array with a bunch unnecessary "true" values? $PID = intval ($_GET['pid']); if(!isset($_SESSION['items_viewed']) || !in_array($PID, $_SESSION['items_viewed'])) { $_SESSION['items_viewed'][] = $PID; //Update database } Note; the isset() check would not be needed if that session variable is created when the user first accesses the site or logs in for instance.
  24. That statement is incorrect. There is no reason any HTML code has to be in or outside the PHP tags as long as it is being properly formatted based on the context and the desired output. I see specifically nothing wrong with the code the OP last posted. But, since he didn't post what the output is that he is getting there's no way to know what the problem is.
  25. I'm guessing the problem is that there may be white-space characters (spaces, tabs etc.) that you are not accounting for. Try this $pattern = "#</tbody>[^<]*</table>[^<]*</td>[^<]*<td>[^<]*<table[^>]*>[^<]*<tbody>#is"; $content = preg_replace($pattern, "", $content);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.