Jump to content

blepblep

Members
  • Posts

    89
  • Joined

  • Last visited

    Never

Everything posted by blepblep

  1. Thanks batwimp, I'll have a look at doing that once I get some more things sorted with my site. Appreciate the help! Any idea why my query isnt working? It's not giving me out any errors but it's not working either. Muddy was saying something earlier about it: I'm not sure how to tell the query which field ID in the database it is supposed to update.
  2. @Batwimp - Thanks, I've changed it to how you've said. @Adam -I don't really understand how to do that. Do you mean I should have checkfields on each of the text box's that I want the user to fill in to verify that they have been filled in or what? Sorry about this, I've just been learning PHP about 2-3 months
  3. This is what happens when I do the sanitize like this - function sanitize_data($data) // create the function sanitize_data { $data = array_map('trim',$data); $data = array_map('strip_tags',$data); $data = array_map('htmlspecialchars',$data); $data = array_map('mysql_real_escape_string',$data); return $data; } $post = array(); foreach($_POST as $key =>$value){ $post[$key] = sanitize_data($value); // call sanitize_data using each value from the $post array } I get this - Thanks for the help so far guys
  4. var_dump($post); if(isset($post['save'])) Results in: NULL So no, nothing is getting passed in either!
  5. Thanks Muddy, I've changed my function sanitize_data($data) to this: function sanitize_data($data) { $post = array(); foreach ($_POST as $key => $value) { $post[$key] = sanitize_data($value); } } if(isset($post['save'])) { $insert_query = "UPDATE tc_tool.forms SET booking_number = '{$post['booking_number']}', .............. WHERE (id = $_id)"; I don't get any errors now when I click save, and it doesn't create a new ID, but still doesn't save to the ID it's supposed to be updating. I thought I could tell the query which ID field in the database it's meant to update by doing something like this? WHERE (id = $post[review_id])"; // or WHERE (id = $post['review_id'))"; But neither give me an error, ahhh!!
  6. I don't really understand what you mean by I need to have a php variable that contains the id of the record I'm trying to add? Or the sanitizing all the inputs This is how it looks at the moment: <?php ///------------------------ /// Connecting to database ///------------------------ include 'connect_db.php'; ///----------------------------- /// Inserting data into database ///----------------------------- function sanitize_data($data) { $data = array_map('trim',$data); $data = array_map('strip_tags',$data); $data = array_map('htmlspecialchars',$data); $data = array_map('mysql_real_escape_string',$data); return $data; } $post = sanitize_data($_POST); if(isset($_POST['save'])) { $insert_query = "UPDATE tc_tool.forms SET booking_number = '{$_POST['booking_number']}', quality_ranking_review = '{$_POST['quality_ranking_review']}', input_doc_rank = '{$_POST['input_doc_rank']}', correct_doc = '{$_POST['correct_doc']}', internally_reviewed = '{$_POST['internally_reviewed']}', reqs_covered = '{$_POST['reqs_covered']}', correct_storage_library = '{$_POST['correct_storage_library']}', reports_described = '{$_POST['reports_described']}', approved_change_requests_included = '{$_POST['approved_change_requests_included']}', issues_addressed = '{$_POST['issues_addressed']}', doc_available = '{$_POST['doc_available']}', statement_problem_chapter = '{$_POST['statement_problem_chapter']}', major_comments = '{$_POST['major_comments']}', result = '{$_POST['result']}', num_of_major_comments = '{$_POST['num_of_major_comments']}', minor_comments = '{$_POST['minor_comments']}', next_review_forum = '{$_POST['minor_comments']}', date = '{$_POST['date']}', time = '{$_POST['time']}', venue = '{$_POST['venue']}', time2 = '{$_POST['time2']}', location = '{$_POST['location']}', severity = '{$_POST['severity']}', resp = '{$_POST['resp']}', status = '{$_POST['status']}', comment = '{$_POST['comment']}', remark = '{$_POST['remark']}', miscellaneous = '{$_POST['miscellaneous']}' WHERE (review_id = $id)"; //----------------------------- // Prints error if there is one //----------------------------- if (!mysql_query($insert_query, $connection)) { echo "Query failed: $query<br />" . mysql_error(); } mysql_close($connection); } ?> My id row in my database is called review_id but that doesnt make any difference to whats being done.
  7. Thanks for the help Muddy!! I get this error when I run it: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' quality_ranking_review = '',, input_doc_rank = '',, correc' at line 3 As for id, it is being stored in the database as review_id. I have it sanitized by doing this - function sanitize_data($data) { $data = array_map('trim',$data); $data = array_map('strip_tags',$data); $data = array_map('htmlspecialchars',$data); $data = array_map('mysql_real_escape_string',$data); return $data; } $post = sanitize_data($_POST); if(isset($_POST['insert2']))
  8. Tried it these ways too - if(isset($_POST['insert2'])) { $insert_query = "UPDATE tc_tool.forms SET booking_number = 'booking_number', quality_ranking_review = 'quality_ranking_review', input_doc_rank = 'input_doc_rank', correct_doc = 'correct_doc', internally_reviewed = 'internally_reviewed', reqs_covered = 'reqs_covered', correct_storage_library = 'correct_storage_library', reports_described = 'reports_described', approved_change_requests_included = 'approved_change_requests_included', issues_addressed = 'issues_addressed', doc_available = 'doc_available', statement_problem_chapter = 'statement_problem_chapter', major_comments = 'major_comments', result = 'result', num_of_major_comments = 'num_of_major_comments', minor_comments = 'minor_comments', next_review_forum = 'next_review_forum', date = 'date', time = 'time', venue = 'venue', time2 = 'time2', location = 'location', severity = 'severity', resp = 'resp', status = 'status', comment = 'comment', remark = 'remark', miscellaneous = 'miscellaneous' WHERE (booking_number, quality_ranking_review, input_doc_rank, correct_doc, internally_reviewed, reqs_covered, correct_storage_library, reports_described, approved_change_requests_included, issues_addressed, doc_available, statement_problem_chapter, major_comments, result, num_of_major_comments, minor_comments, next_review_forum, date, time, venue, time2, location, severity, resp, status, comment, remark, miscellaneous) VALUES ( '$_POST[booking_number]', '$_POST[quality_ranking_review]', '$_POST[input_doc_rank]', '$_POST[correct_doc]', '$_POST[internally_reviewed]', '$_POST[reqs_covered]', '$_POST[correct_storage_library]', '$_POST[reports_described]', '$_POST[approved_change_requests_included]', '$_POST[issues_addressed]', '$_POST[doc_available]', '$_POST[statement_problem_chapter]', '$_POST[major_comments]', '$_POST[result]', '$_POST[num_of_major_comments]', '$_POST[minor_comments]', '$_POST[next_review_forum]', '$_POST[date]', '$_POST[time]', '$_POST[venue]', '$_POST[time2]', '$_POST[location]', '$_POST[severity]', '$_POST[resp]', '$_POST[status]', '$_POST[comment]', '$_POST[remark]', '$_POST[miscellaneous]')"; Get this error - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ( '', '', '', '', '', '', ''' at line 63 This way - if(isset($_POST['insert2'])) { $insert_query = "UPDATE tc_tool.forms SET booking_number = 'booking_number', quality_ranking_review = 'quality_ranking_review', input_doc_rank = 'input_doc_rank', correct_doc = 'correct_doc', internally_reviewed = 'internally_reviewed', reqs_covered = 'reqs_covered', correct_storage_library = 'correct_storage_library', reports_described = 'reports_described', approved_change_requests_included = 'approved_change_requests_included', issues_addressed = 'issues_addressed', doc_available = 'doc_available', statement_problem_chapter = 'statement_problem_chapter', major_comments = 'major_comments', result = 'result', num_of_major_comments = 'num_of_major_comments', minor_comments = 'minor_comments', next_review_forum = 'next_review_forum', date = 'date', time = 'time', venue = 'venue', time2 = 'time2', location = 'location', severity = 'severity', resp = 'resp', status = 'status', comment = 'comment', remark = 'remark', miscellaneous = 'miscellaneous' WHERE (booking_number, quality_ranking_review, input_doc_rank, correct_doc, internally_reviewed, reqs_covered, correct_storage_library, reports_described, approved_change_requests_included, issues_addressed, doc_available, statement_problem_chapter, major_comments, result, num_of_major_comments, minor_comments, next_review_forum, date, time, venue, time2, location, severity, resp, status, comment, remark, miscellaneous)"; Results in this error - Operand should contain 1 column(s) I want to store this information in the database too so I'm not sure if a UPDATE statement is right, as this is new information being passed into the database but I want the ID of this new information to be the same as the ID that was searched if that is any clearer? I don't understand why it's incrementing the ID in the database each time the button is clicked
  9. Thanks for the reply, I've tried it using an UPDATE query: $insert_query = "UPDATE tc_tool.forms WHERE (booking_number, ................ ) VALUES ( '$_POST[booking_number]', But I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (booking_number, quality_ranking_review, input_doc_rank, ' at line 1 I'm not really sure why I'm getting that error
  10. I don't really no what code to show but here goes, any more needed just ask - Button code on the results page: <form action = "saveMom.php" method = "post"> <tr> <td> <input type="button" name="reset_form" value="Clear Fields" onclick="this.form.reset();"> <input type="submit" name="insert2" value="Save MOM" /> </td> </tr> Inserting the data: if(isset($_POST['insert2'])) { $insert_query = "INSERT INTO tc_tool.forms ........... VALUES ( '$_POST[booking_number]', .......... } Should I have the insert data to the database on the same page as the results or would that make a difference?!
  11. Hi guys, hoping for some help here. I've a database created with a website. I recently got help here off Muddy Funster who was a MASSIVE help to me on this thread - http://www.phpfreaks.com/forums/index.php?topic=357580.new;topicseen#new I've another slight problem with what I am trying to do. At the moment the user can search for an ID and it brings up the relevant information. What I am doing now is that the user has entered the ID, their taken to the results where they can be viewed. What I have added is a form at the bottom of the results page, which has to be filled in and saved. I thought this would be relatively easy. I have the form storing in the database, but there is one problem, its being added as another document! So instead of clicking save and the information being added to the ID that is already associated with it, it is incrementing the ID in the database and being stored separately to the ID that was searched. Could anyone give any help as to why this might be happening? I have on the button 'Save' click, it goes to another php file and inserts the data to the relevant fields, I'm not sure why it is incrementing the ID separately instead of just saving to the ID that it is associated with I don't no if I'm making it clear enough but what I wanted to do was save the form they filled out with the ID that was searched if you get me? Thanks for any help
  12. Yeah thats perfect, thanks alot!! I have some other stuff now to try and implement on search, I wont ask as you've answered enough, I'll try it now and see how it goes.
  13. Yep, it works also, you are a genius Muddy, cannot thank you enough! Would you be able to explain this function a little please if you have the time? Not too sure how it works. function custOut($val){ if (is_array($val)){ foreach($val as $k=> $v){ if(trim($v) == '' || empty($v) || !isset($v)){ $v = 'N/A'; } } } else{ if(trim($val) == '' || empty($val) || !isset($val)){ $val = 'N/A'; } } return $val; }
  14. Cool thanks, I fixed the query now! But now that I've gotten rid of the fields that aren't relevant to the forms (Instead of having N/A), when I search it still displays nothing if I put in the - if($num != 0) { while($row = mysql_fetch_assoc($data)) //this will check each result and replace any empty fields with 'N/A' foreach($row as $k => $v) { if(trim($v) == '') { $v = 'N/A'; } } And if I take out the foreach of above, it displays the search results but still shows blank fields. Would it be better to leave the fields as N/A in the form, submit them to the database or is there a way I can do what you showed, like pass in N/A to the returned search fields so they wont be left blank?
  15. Sorry I don't really understand to be honest. The reason I need N/A is because I'm using only oneDB, and if full or simplified isn't used in one form it is used in another if you get me? If I don't store something in the database (Like N/A for example) I get an error saying Query doesn't match column count, so I have to have some value being passed into the fields that are not needed. // Prints out details related to ID entered if($num != 0) { while($row = mysql_fetch_assoc($data)) //------------------------------ //this will check each result and replace any empty fields with 'N/A' foreach($row as $k => $v) { if(trim($v) == '') { $v = 'N/A'; } } //------------------------------ { echo "<b>Document ID:</b> {$row['doc_id']}<br />". But it doesnt displaying anything that was entered when I search for the document, it leaves everything blank..
  16. Cool, thanks Muddy. I've one more question if you dont mind me asking. In my forms, I have certain fields that are not applicable to each forms, so in the fields that are not applicable they say N/A. But the N/A fields have to be there as they are in all of the forms. The one problem I have with this is that the value N/A doesnt store in the database or display in the form when the ID is entered to search for. Have you any idea how I can get the N/A to display in the form when the ID is searched and have it store in the database too, without the user having to type it in? This is one field that is N/A - <tr> <td>Review Duration</td> <td><input type = "text" size = "51" name = "review_duration" value = "N/A" readonly = "readonly"/></td> </tr> And then when searched it appears like this, the fields that are meant to say N/A are the ones that have nothing beside them like Full or Simplified etc -
  17. Ahhhh balls, this doesnt work in Internet Explorer!!! Search returns nothing in IE, can never be straight forward :'(
  18. Thanks Muddy for all the help, really appreciate it.
  19. What do you mean, something like this is it Muddy? if($num != 0) { while($row = mysql_fetch_assoc($data)) { echo "...... ....." else{ echo "Sorry, no entry for that ID, please enter another."; }
  20. IT WORKS!!!!! YES! Thank you so much Muddy, really really appreciate it. Thanks A LOT man!! :D :D Can I ask you another thing, in my database my most recent entry is 342, when I enter 341 or below nothing appears. Is there any way I can make a message appear saying something like - Sorry, no entry for that ID, please enter another. Any way to do that if someone enters an ID or say 341 or below, or something like 1000? Basically to give an error if an ID doesnt exist in the database.. Thanks again I really appreciate it by the way.
  21. Nope, still not displaying anything Heres a screenshot of my database if this is any help? I thought by echoing ['doc_id'] etc it would display what id it was along with the ['doc_title'] and the rest of them. This is when I browse the table -
  22. I'll just send it to you through pm, it's not live though so I don't no if that will matter?
  23. Yeah I fixed that so it would run. Whenever I run it it goes to the searchByDocID page but displays nothing.. I honestly don't no why this isnt working, would it have anything got to do with how I have this done? As it's not giving me any errors but not displaying anything! Would you like access to my database or what? while ($result = mysql_fetch_array( $data )) { echo $row ['doc_id'] . " <br /> " . $row ['doc_title'] . " <br /> " . $row ['doc_number'] . " <br /> " . $row ['doc_type'] . " <br /> " . $row ['revision'] . " <br /> " . $row ['cdm_link'] . " <br /> " . $row ['mars_link'] . " <br /> " . $row ['checklist_link'] . " <br /> " . $row ['link_internal_1_3']. " <br /> " . $row ['impacted_products']. " <br /> " . $row ['scope']. " <br /> " . $row ['impacted_products_2'] ." <br /> " . $row ['review_class']. " <br /> " . $row ['full_simplified'] . " <br /> " . $row ['pref_earliest'] . " <br /> " . $row ['pref_latest'] . " <br /> " . $row ['prev_reviews'] . " <br /> " . $row ['proj_name'] . " <br /> " . $row ['auth_name'] . " <br /> " . $row ['req_list'] . " <br /> " . $row ['optional_list'] . " <br /> " . $row ['information_only'] . " <br /> " . $row ['chairperson'] . " <br /> " . $row ['req_reviewers'] . " <br /> " . $row ['review_duration'] . " <br /> " . $row ['document_abstract'] . " <br /> "; }
  24. Cool thanks for that. What do you mean make sure and use the form to load the page, not just refresh it?! I've got off the website and came back done it again and entered a number and it keeps showing the error - There was a problem with the form, please try again and make sure you have filled in a document number
×
×
  • 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.