-
Posts
5,536 -
Joined
-
Days Won
192
Everything posted by mac_gyver
-
one of the reasons for the yyyy-mm-dd format for a DATE data type is because that format is required in order to compare dates by magnitude. other reasons for using a DATE data type include being able to use the mysql DATE functions on the value, the most efficient data storage, and the quickest queries. you need to store your dates as a DATE data type, with that format. to insert dates that have a different format into a DATE data type, you need to reformat them. you can either do this in your php code or you can use the mysql STR_TO_DATE() function in your query.
-
Populating dropdown menu with mysql data problem
mac_gyver replied to bambinou1980's topic in Javascript Help
dynamically adding form fields is typically used when adding empty fields for data entry, such as adding a set of fields to enter the data for each additional person in a family or adding a new car to your insurance coverage... it is not used to reveal existing information, as that just adds extra clicks to the process and makes for a bad user experience on your site. if what you are wanting to do is make the select/option menu contain all the possible products (less ones that have already been picked up to that point), that's not what your code is currently doing and still makes for a 'click happy' bad user experience on your site. if what you are wanting to do is provide a way of selecting among all your products, see my reply in your other thread. -
PHP form what I can add fields with a button.
mac_gyver replied to bambinou1980's topic in PHP Coding Help
making a select/option menu that has only one choice, repeated for each product, makes no sense. what is the purpose of the select/option menu in your code? you would typically display all available products at once, ordered by category and/or name, or if you have a large number of products, provide a search box, category selection menu/links, or use pagination to limit what's being displayed at one time. the one-time non-product information for the order would normally be entered as a separate step, not as part of the product selection. you should not store the three prices in separate columns in your products table. multiple prices should be stored in another table, one row for each price, tied back to the products table using the product id. you can then store any number of prices for any product. when you JOIN the two tables to display the information, you will only get a row in the result set where there is a price. your code to produce the (three) radio buttons would simply loop over however many rows the JOINed query returns and produce that number or radio buttons. any time you find yourself repeating code, that only differs in the value it uses (such as your 3 radio button logic), it's a sign that you should be using a loop of some kind rather than writing out the code n number of times for each possible input value. before you move up to using jquery/ajax, you need to be able to produce the client side and server side code that accomplishes your task, since you will still need all of that client and server code when using jquery/ajax. jquery/ajax isn't required to make certain types of pages work. they only allow you to dynamically do things in the client without refreshing the page. without using them only means that when you perform an action in the client, the resulting output completely comes from the server. -
the following is equivalent, without the extra $myarray that's causing all the data to be stacked together, to what you are showing - while ($row = $result->fetch_assoc()) { file_put_contents("message/{$row['id']}.json", json_encode($row)); }
-
yes, your errors are due to the debugger. php code debuggers generally work by adding a layer of output buffing to send the debugging information to their client module. you should generally only use a debugger to debug why your code isn't doing what you expect (that's why they are called debuggers), not as the primary method of running your code.
-
php include/require statements, unless you specify the syntax for a url (protocol, domain, path, file - i.e. http://your_domain/your_path/your_file.php), operate on files through the file system, where url get parameters - ?some_name=some_value have no meaning. however, you would in general not want to use a url, because it is slow (your web server makes a http request back to your own web server), you only get the OUTPUT from your file, not the actual php code, and the two php settings that are required for a url to work are turned off by default due to the security problem of this allowing unvalidated external values being used to specify included files to allow a hacker to include their remote code onto your server and run it on your server. if your goal is to retrieve some information based on an id and make that information available to the 'calling' code, you would write a function that accepts the id as a parameter and returns the data to the calling program.
-
because you haven't posted any actual output from your code, there's a chance that the error is in your interpretation of the result. also, unix timestamps are not reliable, since an actual conversion between different number systems is required to use them. the following is from mysql's own documentation for it's unix timestamp based functions - why not just store a mysql DATETIME value?
-
to fix your debatable design, you don't need to run the query that doesn't work/times out. you need to select all the rows from the badly designed table, that has the multiple string values stored in the single column, split up those values, get or assign an auto-increment integer id key for each unique string value, then insert row(s), one for each existing row and each original split values, into a new table, with the id corresponding to the string and the id of whatever you are relating that information too. the resulting table should only have integer id values in it. for example, if you have a row in your existing table with only one of these string values stored in the offending column, you would end up inserting one row in the new table. if you have a row in your existing table with three of these string values stored in the single column, you would end up inserting three rows in the new table. once you get finished with this deconstruction/reconstruction process, you would use this new table in JOINed queries to relate, using exact value, integer, matches, the source data in the parent tables. then, by using correct indexes on the tables, you can easily and quickly query tables that contain several millions of rows.
-
Help with designing my mysql tables before coding in PHP
mac_gyver replied to bambinou1980's topic in MySQL Help
in real life applications, data is not actually deleted. if you insert a row into a table and assign it an id (identifier), that row is never deleted, so that any data that uses that id will always be valid. if you want to make a piece of data unavailable at some point, you would have a status column that controls if it can be chosen. yes, you would have a price table that contains the product_id, customer type, and since the price for anything can change over time, a start date and end data that the stored price is applicable. -
the following is your code, rearranged as suggested - <?php // initialization $conn = mysqli_connect("localhost","root","","hsa_project_hub"); session_start(); // user state/permission check if(!$_SESSION['user_loginName']){ header("location: index.php"); exit; // in one your other threads, it was suggested that you add this here. this elimiates the need for the else {} statement - } // else { // not needed if you exit after the header() redirect. you also don't have the closing } in your code in the correct place, so it's best to simply elimiate unnecessary code. i have removed the closing } from this example code. // post method form processing if($_SERVER['REQUEST_METHOD'] == 'POST') // an overall check if a post method form was submitted { //Enter info in database if(isset($_POST['submit_data'])){ //Getting the form information and saving in local variables // $name = mysqli_real_escape_string($conn,$_POST['name']); // this is the RFI number and should be produced by the database $subject = mysqli_real_escape_string($conn,$_POST['subject']); $date_submit = mysqli_real_escape_string($conn,$_POST['date_submit']); $needed_by = mysqli_real_escape_string($conn,$_POST['needed_by']); $question = mysqli_real_escape_string($conn,$_POST['question']); $gc_rsp = mysqli_real_escape_string($conn,$_POST['gc_rsp']); $owner_rsp = mysqli_real_escape_string($conn,$_POST['owner_rsp']); $engr_rsp = mysqli_real_escape_string($conn,$_POST['engr_rsp']); $arch_rsp = mysqli_real_escape_string($conn,$_POST['arch_rsp']); $final_by = mysqli_real_escape_string($conn,$_POST['final_by']); $date_returned = mysqli_real_escape_string($conn,$_POST['date_returned']); $status = mysqli_real_escape_string($conn,$_POST['status']); // Creating local variable for query from Session variable $first_name = $_SESSION['firstName']; $project_id = $_SESSION['project_id']; $sql = " INSERT INTO rfis ( id, name, subject, issued_by, date_submit, needed_by, question, gc_rsp, owner_rsp, engr_rsp, arch_rsp, final_by, date_returned, status ) VALUES ( '$project_id', '$name', '$subject', '$first_name', '$date_submit', '$needed_by', '$question', '$gc_rsp', '$owner_rsp', '$engr_rsp', '$arch_rsp', '$final_by', '$date_returned', '$status' ) "; if (mysqli_query($conn, $sql)) { echo "Success with first query"; // at this point you can get the auto-increment id that was assigned to the inserted row // all the code that's dependetn on the INSERT query working would need to be here or would need to check for errors from the above code (you would have to actually set elements in the $errors array to do this.) } else { // you ALWAYS need to handle errors. if you use trigger_error() you can display them when devloping/debugging and log them on a live server since trigger_error() uses php's error_reporting/display_errors/log_errors settings //echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } // the following section of code goes-a-way once you use the auto-increment value from the INSERT query //Fetch new RFI No. from database /* $s = "SELECT rfis.id,rfis.name\n" . "FROM rfis\n" . "where rfis.id=$project_id\n" . "and rfis.name=$name"; $result=mysqli_query($conn,$s); $row=mysqli_fetch_assoc($result); $i=0; $run = mysqli_query($conn, $s); //assign values to local variables while($row=mysqli_fetch_array($run)){ $rfiNo =$row["name"]; $i++; } */ // the following code is part of the form processing. you should validate the uploaded file infomration when you validate the other form data. // at this point, you will have the auto-increment id value from the INSERT query above. // process uploaded files if(isset($_FILES['files'])){ // unless you exceed the post max size setting, this will be set if the form was submitted. $errors= array(); foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){ $file_name = $key.$_FILES['files']['name'][$key]; $file_size =$_FILES['files']['size'][$key]; $file_tmp =$_FILES['files']['tmp_name'][$key]; $file_type=$_FILES['files']['type'][$key]; if($file_size > 2097152){ $errors[]='File size must be less than 2 MB'; } $query="INSERT into rfi_files(`rfi_id`,`rfi_project_id`,`rfi_fileName`,`rfi_fileSize`,`rfi_fileType`) VALUES('$rfiNo','$project_id','$file_name','$file_size','$file_type'); "; $desired_dir="rfi_files"; if(empty($errors)==true){ if(is_dir($desired_dir)==false){ mkdir("$desired_dir", 0700); // Create directory if it does not exist } if(is_dir("$desired_dir/".$file_name)==false){ move_uploaded_file($file_tmp,"$desired_dir/".$file_name); }else{ // rename the file if another one exist $new_dir="$desired_dir/".$file_name.time(); rename($file_tmp,$new_dir) ; } mysqli_query($conn,$query); }else{ print_r($errors); } } if(empty($error)){ // you have a typo in this line, it should be $errors echo "<script>alert('RFI $rfiNo added successfully')</script>"; echo "<script>window.open('rfi_list.php','_self')</script>"; } } } // get method business logic (produces/retrieves data needed to display the page) // in this case, you are not producing/retrieving any data (if you were editing an existing record, you would retreive that data here...) // the dividing line between the business logic and the presentation logic. you can close any database connection since you are done retreiving any database data at this point. // get method presentation logic (uses the data from the business logic and produces the dynamic output for the page) // if the output doesn't require any heavy processing/formatting, just use the data directly in the html page/template code. // again, not used in this case // html page/template (the actual html document that the dynamic output is put into to make the complete page.) // only simple php conditional logic/loops and echo statements should be present beyond this point. ?> <!DOCTYPE HTML> <html> <head> <title>New RFI</title> <link href="hsastyle.css" rel="stylesheet"> <link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'> <style> form label { float: left; width: 150px; margin-bottom: 5px; margin-top: 5px; padding: 5px; } .clear { display: block; clear: both; width: 100%; } #rfi_container { background: #F0F0F0; font-family: 'Josefin Sans', sans-serif; font-weight: bold; color: #8F0000; } #files { background: yellow; display:block; } </style> </head> <body> <div id="main_container"> <p><em>version 1.0 beta</em></p> <div id="banner"> <div id="logo"> <img src="images/hsa-logo.jpg" alt=HSA logo> </div> <div id="logout"><H5><a href="logout.php">Log Out</a></H5></div> <div id="welcome"><h6>Welcome <?php echo $_SESSION['firstName'];?></h6></div> <div id="project_name"> <strong><em><?php echo $_SESSION['projName']?></em></strong> </div> </div> <!--End Banner--> <div id="user_list"> <FORM> <INPUT Type="BUTTON" Value="Back to RFI List" Onclick="window.location.href='rfi_list.php'"> </FORM> </div> <div id="rfi_container"> <!--Create RFI for user input--> <form id="form1" name="form1" method="post" action="new_rfi.php" enctype="multipart/form-data"><br> <br class="clear" /> <label for="name">RFI NO.</label><input type="text" name="name" id="name" placeholder="Ex: 003" required="required" /> <br class="clear" /> <label for="subject">Subject</label><input type="text" name="subject" id="subject" placeholder="Ex: Discontinued floor finish" /> <br class="clear" /> <label for="date_submit">Date submitted:</label><input type="date" name="date_submit" id="date_submit" /> <br class="clear" /> <label for="needed_by">Date Needed by:</label><input type="date" name="needed_by" id="needed_by" /> <br class="clear" /> <label for="question">Question:</label><textarea name="question" id="question" required="required" cols="100" rows="5"></textarea> <br class="clear" /> <label for="gc_rsp">Contractor Suggestion:</label><textarea name="gc_rsp" id="gc_rsp" cols="100" rows="5"></textarea> <br class="clear" /> <label for="owner_rsp">Owner Response:</label><textarea name="owner_rsp" id="owner_rsp" cols="100" rows="5"></textarea> <br class="clear" /> <label for="engr_rsp">Engineer Response:</label><textarea name="engr_rsp" id="engr_rsp" cols="100" rows="5"></textarea> <br class="clear" /> <label for="arch_rsp">Architect Response:</label><textarea name="arch_rsp" id="arch_rsp" cols="100" rows="5"></textarea><br> <br class="clear" /> <label for="final_by">Final Response by:</label><select name="final_by" id="final_by"> <option></option> <option value="Architect">Architect</option> <option value="Owner">Owner</option> <option value="Structural Engineer">Structural Engineer</option> <option value="MEP Engineer">MEP Engineer</option> <option value="Civil Engineer">Civil Engineer</option> <option value="Landscape Architect">Landscape Architect</option> </select> <br class="clear" /> <label for="date_returned">Date Returned:</label><input type="date" name="date_returned" id="date_returned" /><br> <br class="clear" /> <label for="status">Status:</label><select name="status" id="status"> <option></option> <option value="CLOSED">CLOSED</option> <option value="at Architect">at Architect</option> <option value="at MEP Engineer">at MEP Engineer</option> <option value="at Structural Engineer">at Structural Engineer</option> <option value="at Civil Engineer">at Civil Engineer</option> <option value="at Landscape Architect">at Landscape Architect</option> <option value="at Owner">at Owner</option> <option value="at General Contractor">at General Contractor</option> </select> <br class="clear" /><br> <input type="file" name="files[]" multiple="" /> <br class="clear" /><br> <center><input type="submit" name="submit_data" id="submit_data" value="Submit RFI" /></center> </form> <br> <!--<div id="files"><a href="rfi_files<?php// echo $rfiFilename;?>"><?php //echo $rfiFilename;?></a></div> USE LATER TO SHOW LINK FOR DOWNLOAD--> <div><!--end of container--> </body> </html> note: i didn't actually FIX anything in this code, it may in fact have php syntax errors. other than a few minor changes, which are commented, there are only comments added to this code or commented out code.
-
some things to consider - 1) this form/form processing is for creating a RFI. it shouldn't be up to the user to enter/manage the RFI number (and if he was, the form field name, php variables, and database column name should all match and have a name the reflects the purpose of the value.) you should use an auto-increment column in your database table to manage the RFI number. 2) ALL the form processing code that belongs to one form should be together, inside one logic test. your code around line 200 isn't even inside of any form processing logic and will be executed each time the page gets requested. 3) you need to arrange your code better. any post method form processing code should come near the start of your file. your code should be laid out in this general order - initialization, user state/permission check, post method form processing, get method business logic (produces/retrieves data needed to display the page), get method presentation logic (uses the data from the business logic and produces the dynamic output for the page), html page/template (the actual html document that the dynamic output is put into to make the complete page.) doing this will reduce the amount of code, because it will consolidate the different sections that you now have scattered throughout your file. it will also make it easier to test each section and then to only post the relevant section if you need help. so, if the database is creating/managing the RFI number, after you successful INSERT the new row, you can retrieve the just assigned auto-increment id by calling mysqli_insert_id($conn)
-
the file of code in post #5 isn't running any code. that's just the class definition. browsing to that file WON'T produce any output. you would need to include/autoload that file, make an instance of that class, and reference the class methods/properties of that class.
-
your code was exit()'ing inside the else {} statement (which had nothing to do with a mysqli error, it matched your if (isset($_POST['submit']) ... statement) and never reached the <form>. after the change you made, it's still exit()'ing. why do you have that exit(); statement in your code?
-
pls help: php upload via url not working fine
mac_gyver replied to Oliverkahn's topic in PHP Coding Help
the settings that allow statements to read a file using a url are usually turned off. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would be reporting and display any errors it detects? -
sorry if this sounds too blunt, but you cannot program if you aren't looking at and learning what the statements in the code are doing. in your previous thread, you were selecting a database. in this code you are not. you cannot run a database query query unless you select a database or explicitly list the database name in the query. in your previous thread someone suggest setting php's error_reporting/display_errors settings, adding error checking logic to your database queries, and testing if queries match any rows. where is your code that's doing these things? if you always do these things, php and your code will tell you when something fails, where is it failing at, and why, or at least where to start looking to find out why it failed. you also should not be trying to use the mysql_ statements. they are obsolete and will be removed from php in the future. what you are learning now will be out of date and the code you are writing will stop working and need to be rewritten. you had mysqli_ statements in your last thread. you should have corrected that code to use ALL mysqli_ statements.
-
the code you posted above is a race-condition waiting to happen. unless you lock the table, you CANNOT select data and increment the highest value and be sure that you don't have concurrent visitors doing the same thing at the same time, producing the same end value. in fact, since it's going to take a relatively long time (in terms of computing) to retrieve all the rows, there's an even bigger window of time where multiple visitors can be trying to run that same code. why aren't you using an auto-increment column as the invoice number?
-
your's is the first post i have ever seen that has indicated a problem with not getting a data() and given you have had this on different servers and php versions and that most problems are due to code and not underlying bugs, it's more likely that the problem is something like register_globals (in php versions where it exists) overwriting the $invoice_number variable or some handling of the value (in code or the database) is truncating it/clearing it. the 'njis' format string will generate a 6, 7, or 8 character string. perhaps you have some code or data storage that when it is either 6 or 8 characters, that the value is getting cleared? in those cases where you don't get a value, what does your date("njis").rand(11111,99999) value end up being? assuming you are storing these values in a database column, do you have a unique key/index set up on the column, because multiple invoices could be generated during the same second, resulting in duplicate values that could end up resulting in data not being inserted into the database table. also, what is the data type of the column (you could be generating values that are out of range or invalid for the type, resulting in a zero or an empty string being inserted instead.) it's also possible that your code is being requested twice on occasion, once with and once without expected external data and the execution path the code takes results in a value being generated and inserted into your database that's not what you expect. another common occurrence for unexplained operation of code that are redirects that don't have exit; statements after them and the code that continues to run after the redirect does unexpected things to data, since that code isn't receiving the inputs that it expects. you could also have code that is updating a properly stored value to an empty value, either due to pages being requested twice/redirects without exit; statements... short-answer: in about 99.7% of all cases of common things php code is used for, incorrect operation of code/data is due to something the code/data is or is not doing, not due to underlying bugs in the language.
-
your post above shows - Posted Today, 08:02 AM for me. i also tried a different browser and the result is the same, 20 minutes behind. my profile settings for time zone is correct. i'll set my time zone to something else, then back to see if it corrects the issue. just more ipb crap. edit: changed my time zone to central and back to mountain and even tried the variations of the DST check-boxes, the hour changed as expected, but the minutes are behind. guessing something in the back-end settings under my username have 'adjusted' the timezone by 20 minutes.
-
the time being shown for posts and the Time Now: being shown at the bottom of pages is currently 19-20 minutes behind real time. in my time zone, it's currently 7:37 am. the time at the bottom of the page is 7:18 am.
-
web servers can handle several 100's of requests per minute. just using the timer/ajax-request method will work for a casual chat system. you would want to make each request/response as brief as possible and make the server side code as efficient as possible, off loading as much formatting/processing onto the client as possible. the client side request, which should be a GET request btw, would include the id of the last message that has been displayed for that user. the server would just query for and retrieve any new messages with id's greater than that id. at a minimum, the message id column in the database table would be indexed. if there's no new messages, the server should return a simple status value to tell the client side code it doesn't need to do anything, perhaps just an empty json encoded array. if there are new messages, just return the raw message data, leave any formatting/display to the client side code. make sure that the database server has query caching turned on as well. when data in the database table hasn't changed, the same database query being made from multiple clients will return data from the cache rather than retrieving it from the database table. you can have 100's of clients all waiting for a new message and they will keep getting the result from the cache that there's no new messages until there actually is one that was stored into the database table, altering it, which causes the cache to be cleared so that it will then cache the new message(s) for the next series of update requests.
- 10 replies
-
in the context of a monthly calendar, what do you want to display? displaying every open time slot for even one trainer (what if you have 20 trainers) would not be piratical. your monthly calendar could at best show a clickable 'event' on the days that have available bookings (and a non-clickable, 'full' listing for days that have no open time slots), either just one event total, if any of the selected/filtered trainers have an opening, or one event for each selected/filtered trainer that has an opening on that date, with a hoover/pop-open tool or a link that gives you a view/page that consists of the booking grid with the open time slots for the clicked on date. a monthly calender could be used for the appointment confirmation. you could display an 'event' on any days that have any un-confirmed appointment(s), for the currently logged in trainer. clicking on the 'event' would take that trainer to a grid of un-confirmed appointments that can then be reviewed and approved. assuming that a trainer would have the need to cancel an appointment, you would instead display an 'event' for all days that the trainer is available. clicking on any day would take the trainer to a grid that shows un-approved and approved appointments on that day with choices to approve/cancel each appointment.
- 30 replies
-
- php calendar
- mysql
-
(and 2 more)
Tagged with:
-
there are existing resource availability/resource reservation scripts that probably do this in some fashion (likely for reserving/booking rooms, rather than a trainer, but the logic is the same.) you would need a table to hold the resource (trainer) availability schedule, all resources in stored in the same table, using a resource id to identify which rows are for each resource. for reoccurring schedules, you would need to store the definition of the schedule (Mike is available on Mondays-Friday from 8am-5pm) and evaluate it, storing the resulting dates and times in the availability schedule table, as needed (any query displaying data with a date higher than the latest stored date would evaluate the definition to populate dates up to at least the latest display date.) you would have a second table to hold resource reservations, with the resource id, the id of who is requesting the resource, the date, start time, end time, and a status. the status would indicate if the resource has been requested (someone selected a date/time slot, but it has not been confirmed) or booked (if the trainer has reviewed and confirmed the reservation.) any resource reservation with either of those status values would not be available for selection. if there is a preference for a particular resource or type of resource, you would get and apply a filter in the query that determines which resource id(s) you match in the resource schedule table and for just the date(s) you are trying to display. you would then join the rows from that table with the resource reservation table, using the resource id and date columns, to get the row(s) and therefore the start/end times the resource is (is not) available for selection. that should get you the data you need to display a grid of appointment slots that are (are not) available for selection.
- 30 replies
-
- php calendar
- mysql
-
(and 2 more)
Tagged with:
-
besides listing what you want, do you have a specific programming question or a problem you need help with?
- 30 replies
-
- php calendar
- mysql
-
(and 2 more)
Tagged with:
-
and, even if the session variable are being set as expected in the login() function, if the session start on that page has failed (there would be php errors), the login isn't actually working because the session variables will only exist as local variables and won't be propagated between pages. did you set the error_reporting/display_errors settings on each page or better yet those should be set in your php.ini on your development system so you don't need to remember to put them into code for debugging and remove them when you put your code onto a live server.
-
the suggestion to use a bootable linux cd wasn't to install linux, it was to boot to an environment where windows isn't running so that you can delete the file without it being locked by the windows operating system.