-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
Please use the forum's bbcode tags (the edit form's <> button) around code when posting it in the forum. I edited your previous post, but i see that you have posted yet more code. please edit your post above.
-
The Form Submits Again on Page Reload - How to Avoid That?
mac_gyver replied to glassfish's topic in PHP Coding Help
i'm not sure if this is an English language problem and you don't understand the meaning of the words or if you don't understand your code. the form processing code is the code that receives the form data and does something with it. in your case, it is inserting a row into a database table. your form processing code starts with the comment - // To insert the text data into the MySQL database. -
the video you linked to adds an unnecessary step of connecting to a local server using ftp. most people directly edit files on their local server. the video you linked to also using a browser with the localhost address to request the file through the xampp apache web server, which is exactly what was stated multiple times in this thread. likewise, the 2013 reply above your's is a repeat of information already given in the thread. topic locked.
-
The Form Submits Again on Page Reload - How to Avoid That?
mac_gyver replied to glassfish's topic in PHP Coding Help
your code is currently generating a new unique id that replaces the previous one before you run the form processing code, so of course the values will never match. your form processing code needs to be positioned in your .php file before any code that displays the data on the page and before you display the form. there are four reasons for this - 1) so that any new data that was just inserted into the database table will appear when you display the data from the database table on the page (assuming you are not redirecting after processing the form data.) 2) so that any form validation errors can be displayed when you re-display the form. 3) so that the unique id that was generated right before the form was output will still be in the session variable when the form processing code runs. 4) so that the second thing mentioned in that linked to thread, of redirecting after you have successfully processed the form data, can occur, since you cannot output anything to the browser prior to using a header() redirect. -
the reason the two values are empty in the sql statement is because the code is using mysqli_real_escape_string() and you likely don't have a mysqli database connection, resulting in null values. if php's error reporting was on, you would be getting php errors alerting you to this problem. 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 to get php to help you. you will save a ton of time. you cannot mix mysql_ (no i) and mysqli_ (with an i) functions. you must use all the same functions that match the type of database connection statement you used. however, the mysql_ functions, which is what you have shown in the first code in this thread, are obsolete and you should not be using them when writing new code. you should be using either the mysqli_ or PDO database functions.
-
given that in your previous threads on this forum, you successfully used a mysql_ fetch statement in a while(){} loop to loop over the rows that a query returned, why not try that same method now? just because you changed from using the mysql_ functions to PDO functions doesn't mean that the fundamental concepts used in the php code changed too.
-
The Form Submits Again on Page Reload - How to Avoid That?
mac_gyver replied to glassfish's topic in PHP Coding Help
this is a very common question and was recently addressed - http://forums.phpfreaks.com/topic/291436-need-help-to-not-resubmit-info-when-refreshing/?do=findComment&comment=1492711 -
you would need to show us how you are dynamically adding elements to the form, i.e. we need to see all the relevant code that would be needed to reproduce the problem. my guess is the added elements don't have an ltotal[] field and your code is looping over the existing database rows ltotal values. your code is also inserting all the submitted form data (existing and dynamically added elements), which doesn't make sense as that would duplicate rows in the database table. lastly, what is the $_POST data - echo '<pre>',print_r($_POST,true),'</pre>'; edit: i have a recommendation for your $status value. rather than using non-descriptive values like 1,2,... use defined constants that would result in meaningful constant names for those values - define('STATUS_CHECKED',1); define('STATUS_UNCHECKED',2); then your code using those values would look and read like - if ($ltotal == '0.00'){ $lstatus = STATUS_UNCHECKED; } else { $lstatus = STATUS_CHECKED; } and - if($status == STATUS_CHECKED) { $active = "checked"; } else { $active = "unchecked"; }
-
the problem is the ; on the end of the - foreach ($EventTotals as $DATA); edit: what the ; is doing is terminating the foreach() statement. the foreach() is actually looping over all elements of the array, but the {echo ...} isn't part of the loop. when the loop finishes, the {echo ...} is executed once as inline code and echos what's in $DATA after the last pass through the loop.
-
Need help to not resubmit info when refreshing
mac_gyver replied to cobusbo's topic in PHP Coding Help
session_start() must be used before you send anything else to the browser. it must be the first thing in your code on the page. -
Need help to not resubmit info when refreshing
mac_gyver replied to cobusbo's topic in PHP Coding Help
there are two things to do to address re-submitting form data. the first one address preventing the data from being processed again. the second one is to make the 'user' experience better (i.e. prevent the browser from displaying any of the resubmit form data/expired page-form messages.) 1) each time you output the form, you need to produce a unique-random one-use 'token' that's put into a hidden form field and stored in a session variable. when the form is submitted, you test that the session variable exists, is not empty, and that it matches the value from the hidden form field to serve as a condition for even processing the form data. you clear the session variable in the form processing code, which causes the form processing code to skip processing any re-submission of the form data. this also helps to prevent a bot script/someone from requesting your form once and using it to keep submitting comments. they must actually receive your form with a new token value to be able to submit a comment. 2) after you have successfully processed the form data (inserted it into the database table), you need to do a header() redirect to the exact same url that the form submitted to. this will cause the last action in the browser for that url to be a GET request for the page and the browser won't attempt to resubmit the form data due to a refresh of the page or navigating to that url. there are some things your current code needs to do that it isn't already doing. your form processing code needs to check that a post method form was submitted at all, so that the form processing code only runs if there is $_POST data and you need to validate that the required form fields are at least not empty. your current code will insert a row with an empty message field every time the page gets requested. -
make sure the database server, database, and table are the correct ones. some possibilities - 1) you have multiple database servers and you are connecting to the wrong one. 2) you have multiple databases and you are selecting the wrong one. note: on case-sensitive operating systems, the database name is case sensitive, so Database_name and database_name would refer to two different databases. 3) same as for #2, but with respect to the table name, including the note about case-sensitivity of the table name. how do you know you have a table with 250 rows? perhaps some rows didn't get imported/inserted? perhaps some rows got deleted?
-
if i had posted that YOUR code is crap, that would have been rude. that's not what anyone stated. likewise, no one stated to remove the GetSQLValueString() function. it was questioned why it was being conditionally defined and if you are duplicating an existing function by having it in the code. that was a question about the code, not a statement to do anything to the code. you would in fact still need that function, which is what the fatal undefined function .... error message you saw means, unless you plan on writing your own code to correctly handle each data value being put into sql query statements (or use prepared queries.) if you keep using it, you will need to properly convert it to use mysqli_real_escape_string() and pass the mysqli connection resource into the function. if you don't plan to keep using it, in addition to correctly handling each data value being put into the sql query statements, you will also need to modify the sql syntax slightly (or use prepared queries), because that function supplies some of the quoting around literal string values, rather than it being in the actual query statement. lastly, mysqli_error(....) requires the mysqli connection resource as a parameter, otherwise you will just get php errors for mysql_error() statement, rather than any database error message.
-
you are selecting the database in the mysqli_connect() statement. there's no need to re-select it, which dreamweaver does before every query statement. in fact, forget most of what DreamWeaver does and just learn to write your own code.
-
this is the kind of crap code that DreamWeaver regurgitates.
-
Using a sql query thats stored in a table on the database.
mac_gyver replied to UKArea's topic in PHP Coding Help
some other things you should and shouldn't do - don't run database queries inside of loops. use one JOINed query to retrieve the related data you want from your tables. separate your database retrieval 'business' logic from your html 'presentation' logic, see this post - http://forums.phpfreaks.com/topic/291210-passing-to-get-beginner-question/page-2?do=findComment&comment=1492189 don't use the old depreciated mysql_ functions, see this - http://php.net/manual/en/mysqlinfo.api.choosing.php edit: also, based on the column names you are using - part_a, part_b, ... you need to give your database columns meaningful names and likely need to normalize the data. -
we cannot really help you without knowing what you are specifically doing. that would take seeing enough of your code and some sample data to be able to reproduce the content. but the subject of this thread, output buffering, would have no noticeable affect on server-side or client-side performance. the only possible affect output buffering would have if you have a TON of html markup (several 10's or 100's of K bytes) on the page and you are using compression (gzip) in conjunction with output buffering on the server and decompressing it in the client to save on the transmission time between the server and the client. this would only save on the transmission time. if you do have a TON of html markup, it must still be rendered in the browser, so it can still take a long time for the page to be displayed, even if your server-side code and the transmission time have been optimized. have you in fact profiled the times taken for everything so that you know where the greatest amount of time is being taken so that you know where to concentrate your effort in optimizing the process?
-
Using the mail() function doesn't work
mac_gyver replied to Tzahi_ben_artzi's topic in PHP Coding Help
when debugging php code, you need to have php's error_reporting set to E_ALL and display_errors set to ON so that php will report and display all the errors it detects. you should have these settings in your php.ini so that they are easy to change in just one place and so that you don't have to remember to put them into code for debugging and remove them when you are done. -
it sounds like you are running database queries in a loop, which is extremely inefficient, since the time taken to communicate the characters making up each query from php to the database server is several times longer than the amount of time most data retrieval queries actually take to run. what sort of problem are you having that you are trying to solve? if you are having a performance problem, the only way of fixing it is to target the problem. the only things that will have a major effect are things that significantly reduce the amount of processing being done or of reducing the total amount of data being manipulated/transferred. output buffering does neither of these things, and in fact it increases the processing time by a very slight amount since php must manage the buffering of the output.
-
see the following link for how you can use an array name for each form field so that the multiple sets of data would all submit their values as an array, which you could then loop over in the php code to access each different set of data - http://us1.php.net/html#faq.html.arrays
-
did you actually try? the + in the link is the encoded space (because space characters are not valid in links). the + will be automatically converted by php (it does a urldecode on $_GET data) to a space and using the value in a database query will work. you could always do what i suggested, which will eliminate the problem of trying to pass a space in the link -
-
encapsulating entire HTML files wiht PHP print function
mac_gyver replied to pjk31337's topic in PHP Coding Help
a) what have you tried? all you did is post what you want. we can only help you with your php code (which is the point of the php coding help forum section) once you have made an attempt and have code to post, along with any errors or symptoms you got from that code that you cannot resolve yourself. b) for a html template code/file there's no need to individually print each separate line of output. you could use one overall print/echo statement with one initial and one final " or just use the herdoc syntax, and if this is all just static html/css/javascript markup with no php variables in it, there's no need to use a print/echo statement at all, just make your html inline by putting a closing ?> tag, followed by your html, then put an opening <?php tag. any inline html is parsed by php and encapsulated for you using a php T_INLINE_HTML token and is output verbatim when executed by php. -
the href='...' attribute in the link is missing the closing ', which is probably breaking the rest of the html on the page. use the following inside the loop - $u = $rows['aquaticCenterName']; $v = urlencode($u); // since this is a text name, make it url encoded $result_tb .= "<a href='reviewResults.php?aquaticCenterName=$v'>$u</a><br>"; i would use the id, not the name, as the value being put into the link - reviewResults.php?id=123 and you can simplify the multiple col LIKE '%$e%' OR ... term in the query to be - $query = "SELECT aquaticCenterName FROM reviews WHERE CONCAT_WS(' ', aquaticCenterName, town, county, country, rating) LIKE '%$e%'";
-
the problem is because your closing </option> tag is actually an opening <option> tag.
-
MySQL & PHP: Associate columns into another table
mac_gyver replied to Nickmadd's topic in PHP Coding Help
i think you are asking how to extract the (unique) data from your existing database table and insert it into a make table, a model table, and a third table that relates the makes and models? please confirm/clarify?