-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
get_included_files only gets the actual files that have been included/required at the time it is called. You would need to use it in a register_shutdown_function to get all the actual included/required files for any particular page request.
-
That line with the } is the point where the re-definition is detected at. Your problem is you are redeclaring the function, either because the definition is inside of a loop or you are including the file, where the definition is at, multiple times.
-
(Beginner) Writing to MySQL from form input
PFMaBiSmAd replied to nathansizemore's topic in PHP Coding Help
You have a spelling error in your query statement, right at the point where the error message is calling your attention to - the right syntax to use near 'INSTERT -
Something tells me that is not all of your php code. Have you even checked if the code is being executed by echoing something in it? What's all the actual php code in your file, including the opening php tags you are using?
-
query is not selecting anything. help?
PFMaBiSmAd replied to Tenaciousmug's topic in PHP Coding Help
The next problem you will have is that you need to call the ->store_result() method before you can access the ->num_rows property. You also don't fetch rows directly from a prepared statement result set using a property called ->fetch_array(). You would use the ->fetch() property. (If you have a high enough version of php, you could use the ->get_result() property followed by a $row = $result->fetch_array(MYSQLI_ASSOC) statement.) You are also going to have a problem with your bind_result() statement because that expects to bind to an actual php variable that you would then reference in the code. I would recommend that you get your mysqli prepared code to work first, before you attempt to write a class that uses it. I'm also going to guess that you don't have php's error_reporting set to E_ALL (or ever better a -1) and display_errors set to ON in your master php.ini to get php to help you. You would have been getting php detected errors in your existing code that would have helped you find where the problems in it are at. Edit: you also have a return statement inside your for(){} loop. That makes no sense. The code would return during the first iteration through the loop and you could never operate on a result set that contains more than one row. You should form an array of the value(s) and then return that array after the end of the loop. Your database class should be general purpose and it should work with any amount of data. -
query is not selecting anything. help?
PFMaBiSmAd replied to Tenaciousmug's topic in PHP Coding Help
After you call the ->stmt_init() method, $this->stmt contains an object that you use with the rest of the statements. Your ->prepare call should be - $this->stmt->prepare($query); -
Upon getting this to work, the answer to your first post in the thread is - echo $result['regyinfo']['registrar'];
-
The showHTML method is for displaying the information. It is not an array of data that you access element of. When you do access a non-existent index of a string, it returns the first character of that string. To access elements of the result, AFAIK (I haven't figured out how to actually use that class based on its excellent documentation - edit: found something useful in the readme file) you would just refer to elements within $result. Edit: What does the following show - echo '<pre>',print_r($result, true),'</pre>';
-
A waiting game.. Is this the best, or is there another way to do this?
PFMaBiSmAd replied to l0gic's topic in PHP Coding Help
You can use a scheduled task on Windows to accomplish the same thing (execute a script at scheduled times/intervals.) -
Queries that SELECT a COUNT(), that don't have a GROUP BY term, only return one row. There's no point in using a loop. Change your while(){} code - while($row = mysql_fetch_array($result)) { echo $row['COUNT(id)'] ; } To just the following - $row = mysql_fetch_array($result); You would then echo $row['COUNT(id)'] wherever you need the value.
-
This str_replace for an external file isnt working!
PFMaBiSmAd replied to Allenph9's topic in PHP Coding Help
You should probably start your own thread for your series of questions. The problem causing each error message you are getting should be fixed so that you only get errors from actual problems so that you can find and fix real problems in your code. The reporting and display/logging of the error message is only the last step in the error response code that php executes EVERY time it detects an error on a page, every time that page gets requested. -
This str_replace for an external file isnt working!
PFMaBiSmAd replied to Allenph9's topic in PHP Coding Help
@Shadowing, You should have error_reporting set to E_ALL (or even better a -1) and display_errors set to ON in your master php.ini on your development system, so that you don't need to remember to put anything into your files or remember to remove it later. Also, by putting these setting into your master php.ini, fatal parse errors in your main file will also be reported and displayed. Putting those settings in your main file won't show fatal parse errors (in your main file, but do show them for any included file) because your code never runs when there is a parse error, so that settings due to lines of code never take effect. -
You need to forget that you ever saw any code using the global keyword inside a function definition. It is NOT the proper way of writing general purpose functions.
-
Here is a truth-ism about programming - Computers are general purpose tools. What they do is completely dependent on what their program logic and data tells them to do. There are multiple different ways of writing code to perform any particular task. The code you wrote is not the only way of accomplishing what it is you are trying to do. A dozen different people could have written code to do what you are trying to do and each of their programs will likely be different, but could still produce the exact same result when it works and the exact same symptom when it does not work. The code you came up with is not uniquely the only way of doing what it is you are trying to do. We don't automatically know what your code is based on your statement of what you are doing and the description of the symptoms. If you thought we could tell what your code is and could tell you what is wrong with it or what to change in it without seeing it, you are wrong. We cannot help you with any of your code without seeing enough of your code that reproduces the symptom that you saw when you tried it. When posting code in the forum, please enclose it within the forum's tags. Edit: I have reviewed some of your posts, and you need to properly indent your code so that you can read it and so that others that you might be asking to help with it will read it as well.
-
Because you are using $row after the end of the while(){} loop, it will contain a false value (the last thing assigned to it.) If you are only getting one row from your database, don't use a loop or if you do use a loop, you would need to assign the value to a variable in the code inside of the loop so that variable would have the only/last value after the end of the loop.
-
Each header() redirect needs an exit; statement after it to prevent the remainder of the code on the page from running while the browser requests the URL that was specified in the Location: attribute.
-
As long as your form submits the data that your form processing code expects, you can produce the form any way you want.
-
This is not due to a buffer holding the output. Your code is running again every time you request the page. An alternate approach is that after you have successfully completed the form processing code, you use a header() redirect to the exact same URL that the form was submitted to. This stores a GET request in the browser's history as the last action for that URL and stops the browser from resubmitting the form data every time you refresh or browse back to that same URL.
-
Since you are listing the team record as part of the displayed information in the form, you would want to dynamically produce the form using php code so the information would be current for every season (gotten out of an array/database table that defines/list the teams) without you manually editing the html in the page.
-
Aren't you already using php to produce the form, so that you can easily change it by simply changing the data structure (array/database table) that defines the list of questions? I'm pretty sure that no one here would even want to type out or copy/paste/alter and then debug the html needed to make 64 similar form elements. Let the computer do that work for you. You don't have to do anything that is suggested, but what I posted above is the optimum way of doing what you asked. It takes the minimum amount of code and executes the fastest.
-
Help with broken PHP pages after server upgrade
PFMaBiSmAd replied to damion's topic in PHP Coding Help
Remove the two @'s (error suppressor operator) that are in front of the mysql_ statements in that code. If your queries are failing due to an error of some kind, you would want to know that (or let php log the errors in the error log file.) The @ error suppressor prevents the display or logging of php detected errors that might be occurring in the statements it is in front of. -
Here's some sample code that shows how to form a multi-value insert query - <?php // fake for testing $uid = 123; // get the user id from wherever you have it at // validate/filter/escape the data here... (use array_map() or array_walk() to operate on the entire $_POST['question'] array at one time) // multi-value insert query with uID, section (1-64), answer foreach($_POST['question'] as $key=>$value){ $data[] = "$uid,$key,'$value'"; } $query = "INSERT INTO user_answer (uID,section,answer) VALUES (". implode('),(',$data) .")"; echo $query; // fake some options for testing $options = "<option value='none'>Select Answer</option>\n<option value='a'>a</option>\n<option value='b'>b</option>\n<option value='c'>c</option>\n"; $form = "<form action='' method='post'>\n"; $questions = range(1,64); foreach($questions as $question){ $form .= "Question $question: <select name='question[$question]'>$options</select><br />\n"; } $form .= "<input type='submit' name='submit'></form>"; echo $form;
-
You would use an array for the form name='...' attribute. name='question[1]' name='question[2]' ... Then $_POST['question'] will be an array of the submitted values - $_POST['question'][1] $_POST['question'][2] ...
-
Also in that code, if the message() function returns to the calling code, your code doesn't actually do anything special when a negative value is detected. Any following code will still use the negative value in $_POST['amount'].
-
Help with broken PHP pages after server upgrade
PFMaBiSmAd replied to damion's topic in PHP Coding Help
The one that is in /home/me/public_html/mysite/php/ isn't or you would not be getting that error.