Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,536
  • Joined

  • Days Won

    192

Everything posted by mac_gyver

  1. ^^^ that appears to be what i surmised. please reread my reply in this thread. you may want to read my reply at the end of your last thread, where maintaining a count in a column can have race conditions that cause data to be lost, and the suggested methods to prevent this.
  2. i recommend that the OP reread (some of) the replies, particularly post #8 (that change applies to both of the statements you have in your code), and the suggestion to please post your current code where the header() redirect statements are at.
  3. @shan, that has nothing to do with any problem in this thread. the OP is already testing a form field that will always exist if the form has been submitted.
  4. that's because the syntax/code that shan posted is incorrect. the correct syntax is what Barand showed in post #8. please post your current code where the header() redirect statements are at.
  5. it would help if you state what it is actually doing, and where it is doing it. if you are only getting part of the message or it is being stripped of any non-ascii characters on the page that the header() redirect goes to, it's probably because you need to use urlencode() on any data you pass through a url
  6. edit ^^^ i'm not trying to write same/similar posts as you, but when i'm logged in, i cannot see (if not logged in i can see) the info at the bottom of a thread that says who, if anyone, is already viewing it and would potentially write a reply. you are apparently asking how to form a column name based on a numeric value, i.e. cn1, cn2, cn3, ... having a series of numbed columns is a bad database design, requiring extra php code and extra queries to just manage the data. whatever this represents either needs to just store the current value (which is what the pad_count already is) or you need a separate table to hold the key/value pairs.
  7. mysql_real_escape_string() requires a database connection to work. therefore, you are getting a null value in $score and should be getting several php error messages. so, three problems - 1) you need to have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on your development system so that php would help you by reporting and displaying all the errors that it detects. you will save a ton of time. 2) don't use any database escape string function until right before you put data into your sql query statement (it's actually better to use prepared queries anyways.) 3) the msyql_ functions are obsolete and will be removed from php soon. you need to learn using the PDO (the best choice) or the mysqli_ database functions so that what you are learning isn't already out of date.
  8. ^^^ and tell use what exact symptom or error you get that leads you to believe these 'aren't working' and do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects? some possibilities - your files either got altered and now have a BOM character saved with them or a .htaccess file or local php.ini file got deleted that was setting some php settings (output_buffering, upload size settings) that are now no longer in effect and are preventing your code from 'working'.
  9. we only see the code you post. it is not missing a ; and does not throw a php syntax error due to that. if you set the php error_reporting/display_errors setting as i suggested, in the php.ini file, and confirmed that the actual settings got changed to those values, you would have been getting a php syntax error at the missing ;
  10. i'm going to guess that the value in your $id_itens variable actually contains double-quotes around it. if you are using print_r($id_itens) and it produced "11" in the output, the only way that can happen is if there are double-quotes in $id_itens. $var = 1; print_r($var); echo '<br>'; $var = '1'; print_r($var); echo '<br>'; $var = "1"; print_r($var); echo '<br>'; $var = '"1"'; print_r($var); echo '<br>'; output - 1 1 1 "1" instead of print_r(), use var_dump() as it also gives the length of whatever is in the variable. so, what is your code that is producing $id_itens?
  11. about the only remaining thing that could be causing this symptom, is if there's a file naming (capitalization matters on a case-sensitive operating system) or permission problem and the web server cannot find or access your file, combined with something preventing a http 404 or related error from being output. check the web server access and error logs to see if there are any errors that correspond to you requesting the file in your browser. this also raises a question, what url did you use in your browser when you requested the page containing the php code with the phpinfo(); statement in it? it should have been something like http://localhost/yourfile.php if nothing else, start over with a new file, with just <?php echo 'something here'; ?> in it, save it to the document root folder, and enter the url, http://localhost/your_filename_here.php in the browser and see what you get. short-answer - this is not that difficult. if you have one .php file that works, but others give no output from the php code and no php errors, there's something you are doing differently between the files that isn't correct.
  12. with a mysqli prepared query, $stmt ->fetch() does NOT return the row, it causes the bound result variables to be populated with the data that is fetched. a) it is much easier to use prepared queries with PDO, not mysqli. b) if your php version is high enough, use the ->get_result() method to convert the result from the mysqli prepared query into a normal mysqli result resource, that you can use a normal ->fetch_assoc() method on. this will also allow you to use the ->fetch_all() method to fetch all the rows into an array.
  13. that would indicate you have html markup in the file, not just the php code you are showing us. perhaps you should show or attach the complete .php file and exactly what the 'view source' of the output is.
  14. if you put an echo 'start'; statement in your file before your $mysqli = new mysqli ... line code and echo 'end'; after your echo $mysqli->host_info . "\n"; line of code, do you get either or both of the start/end being output to the browser?
  15. if the php.ini that you are changing is the one that php is using, and you have confirmed that the settings took effect in the phpinfo() output, any php errors should be displayed in the browser when the .php page is output. in some cases, the php error messages are inside of html tags/form elements and are only visible in the 'view source' of the page in your browser.
  16. there are no semi-colons ; and you will likely need to restart the web server to get any changes to take effect. the phpinfo() output should reflect the changes being made to the two settings.
  17. do you have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on your development system so that php would help you by reporting and displaying all the errors that it detects? you will save a ton of time.
  18. your first query/code should be throwing an error. there is no bound parameter in the sql statement (you cannot bind a table name anyway, you can only bind data values), so the bindparam() doesn't have anything to bind to and the execute() statement should be throwing an error about the number of bound parameters not matching or a similarly worded error.... have you set the PDO error mode to exceptions (it must be done after you make the database connection) so that you would be getting PDO errors (which are different from php errors) from the database statements? since the first query doesn't have any data values being put into it, you can just use the PDO ->query() method to execute that query. for the second query, the two values being put into the sql statement are produced by your code. the $start value is a calculated/assigned integer number, due to the fact that you are multiplying it by the hard-coded integer in $limit and the $limit is a hard-coded value from an assignment statement. if you were getting either of these values from external data (some people do 'rowination', where they are supplying the $start value directly in the 'pagination' links, rather than a logical page number and you can supply a dynamic $limit/rows per page value via a link), you would need to protect against sql injection in the values. so, for how you are producing the two values being put into the sql statement, you can also use the PDO ->query() method for this query.
  19. some code you have, that's either part of the original uploading or downloading of the file, probably contains a new-line character in it, outside of any <?php ?> tags, and this character is getting prepended to the file data.
  20. perhaps you missed this note below the age field in your profile -
  21. you cannot use a setcooke() (or anything else that sends a http header to the browser) after you have sent any characters to the browser. your first echo statement is preventing the second setcooke() statement from working. if you had php's error_reporting set to E_ALL and display_errors set to ON, php would be telling you this. next, the $_COOKIE data comes from the browser. it is only available after the browser requests the page and sends the cookie data to the server. $_COOKIE data is not available on the same page request where it was set using a setcookie() statement.
  22. which you were dong in both sets of code in your previous thread. not trying to give you a hard time (yet), but you must actually learn what each statement you are using does, so that you will know how it contributes to the goal you are trying to achieve, and where it belongs in your code to do it's job. then, when the goal isn't being met, you will have a good idea where to start looking to find what's causing the problem. these are the three different statements you were using in your previous code - $stmt = $db ->prepare (); // prepare an sql statement, that has place-holders in it for inputs $stmt ->bindValue(); // bind actual values to the place-holders in the sql statement $stmt ->execute (); // execute the query so, the flow is prepare, bind inputs, run the query. prepare, bind, execute. prepare, bind, execute... (okay, so now i am giving you a hard time, because you apparently didn't look at your code and try to figure out why it isn't working or what's different about it from the code you wrote before.)
  23. no. the only one who knows what the context is for any line of code and goal you are trying to achieve is the person writing the code. it's up to the programmer to know what the statements being used do, so that they know how they will contribute to the goal being worked on, and to know if they belong in the code at all and where they belong at. putting the correct statements together in a meaningful way to accomplish a goal is the creative part of programming.
  24. there's a comment about that in the first of my posts -
  25. in the time the OP will need to spend to finish adding code to repopulate fields/check-boxes/radio-buttons with existing values, to display errors for each field, and to fix all the other problems in the code, times the number of form fields, and to also fix all the errors caused by typo's in the discrete/hard-coded field/variable names, he can learn enough php so that he would understand what a ternary operator is or to make use of the suggested method. for the OP, here's a basic example that shows the method i suggested for an input type='text' field. all the type= text, password, hidden, and submit fields you currently have would be handled by this method (with the addition of a switch/case statement.) adding code to handle checkbox/radiobuttons is not difficult, with a little php and html knowledge. see the comments in the code in any case. <?php // using arrays, you would define the form fields and just loop over the array to output all the form fields, rather than to write them out by hand // this example shows only one field // notes: // the array key is the form field name. // for the form field type, you would actually have a switch/case statement for the different types to output the correct html for each different type. // the 'value' entry is 'y' to determine if you output any existing value for a field. for a password field, you would typically not output any previously entered value. $fields['userName'] = array('legend'=>'Username','required'=>'y','type'=>'text','value'=>'y'); // you would add the rest of the field definitions here... you can produce the submit buttons too, by defining them in this array // form processing code, first check if a form was submitted - if($_SERVER['REQUEST_METHOD'] == 'POST'){ $errors = array(); // holds validation errors $data = array_map('trim',$_POST); // make a trimmed copy of all post data // check all required fields for being an empty string foreach($fields as $field => $arr){ if(isset($arr['required']) && $arr['required'] == 'y' && $data[$field] == ''){ $errors[$field] = "* {$arr['legend']} is required"; } } // all required fields have been checked for empty at this point, perform additional validation tests here... // you can add rules in the defining array, with things like regex patterns, php string filter function names... and have your code dynamically use that information to validate the fields as you simply loop over them, not hard-code logic for every input // at this point all validation tests have been performed. if there are no errors, you can use the form data if(empty($errors)){ // Insert your code for using the form data here, e.g emailing the submission, entering it into a database. echo 'Done using the form data'; } // if there are no form errors at this point, you would actually do a header() redirect to the same url that the form submtited to, in order to cause a get request for the page. this will clear the post data so that the browser won't try to resubmit the data if you refresh the page or browse back to the same url. // if there are form errors, you would continue on this page and let the following code run to display the form, populate the form with existing data, and display any errors. } // get request code would go here... if you are retrieving data to edit/update it, if the $data array doesn't exsit at this point, the form hasn't been submitted. retrieve any existing data and store it in the $data array. // produce the form, populating it with any existing data values, and display any errors ?> <form method="post"> <?php foreach($fields as $field=>$arr){ // note: this example is only for <input type='...'> fields. to address all the possible types of form fields, you would use a switch/case statement to output the correct markup for each different type echo "<label>{$arr['legend']}: <input type='{$arr['type']}' name='$field' value='".(isset($arr['value']) && $arr['value'] == 'y' && isset($data[$field]) ? $data[$field] : '')."'><span class='error'>".(isset($errors[$field]) ? $errors[$field] : '')."</span></label><br>"; } ?> <input type="submit"> </form>
×
×
  • 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.