Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,370
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. it sounds like the browser is only used to trigger the script, not to provide any input, and that you probably run this script on a regular (scheduled) basis? if so, you would use a cron job/scheduled task to run the script. When the script finishes, it can do anything you want - send an email, update/insert data into a database table indicating when it finished and with what status, log values indicating the same type of info, ...
  2. that particular error means that php reached the end of your file while it was still expecting some closing php syntax. this is usually caused by a missing } but it can also be caused by a quoted string that isn't closed or even using short opening php tags when short opening php tags are not enabled.... you will need to go through your code looking for things that are not matched up. your code does have at least one serious problem. each header() redirect needs an exit; or a die; statement after the redirect to prevent the rest of the code from running while the browser is performing the redirect. the header() doesn't stop the php code. all anyone needs to do is ignore the redirect and they can stay on your page, because all that code still runs. your code also could stand to be organized better. this will reduce the total amount of code you have to write, to debug, to find missing }'s in, ... the biggest things that would help would be - 1) to put all the php code that processes form data and modifies server-side data near the start of your file. 2) put all the code that retrieves data needed to display the page next. 3) have only ONE html document, everything from the <!DOCTYPE tag through to the </html> tag, and have that last in your file. for the different content that you are repeating the html document for now, you would produce the dynamic part of that content and store it in a php variable, then echo that php variable in the ONE single html document.
  3. the WEST abbreviation is correct for your time zone - date_default_timezone_set('Africa/Casablanca'); echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T'); results in this - this suggests that your stored data is incorrect. what's the code that's storing the data? perhaps it is altering the value before storing it?
  4. you're welcome. putting lines of code together so that they accomplish a stated goal is fundamental to this thing called programming. i can guarantee that you learned much more by actually looking at your code and fixing it yourself, than what you would have by someone telling you where to put your fingers on the keyboard and what to type.
  5. if you have the hashed password stored in your database table, how can this part of your query - AND password = '$password' ever be true?
  6. add the new column to your table and run one UPDATE query that populates the new column from the existing column's values. if your existing data contains the commas and spaces, the format-string you use as the parameter in the STR_TO_DATE() mysql function must contain those same characters. that's why a correct design is important, so that you don't have to keep going back and fixing things.
  7. 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.
  8. 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.
  9. 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.
  10. 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)); }
  11. 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.
  12. 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.
  13. 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?
  14. 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.
  15. 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.
  16. 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.
  17. 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)
  18. 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.
  19. 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?
  20. 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?
  21. 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.
  22. INSERT queries don't have WHERE clauses. please read the documentation for whatever you are trying to do - http://dev.mysql.com/doc/refman/5.6/en/insert.html perhaps you you are trying to UPDATE existing information, rather than inserting/creating it?
  23. 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?
  24. try this for the code that combines the arrays - $data = array(); while($row = mysql_fetch_assoc($results)) { $data[$row['id']] = $row; } while($row = mysql_fetch_assoc($results1)) { $data[$row['building_id']] = array_merge(isset($data[$row['building_id']])? $data[$row['building_id']]:array(),$row); } you will also what to sort the final $data array on the key using ksort()
  25. what operating system are you running on the server and what web server are you using?
×
×
  • 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.