-
Posts
5,537 -
Joined
-
Days Won
192
Everything posted by mac_gyver
-
Need help posting to mysql and sending email from form
mac_gyver replied to gabbymiles's topic in PHP Coding Help
you may have tried a bunch of things, but if you didn't echo out the sql query statement so that you (and us) will know what it is (which would also confirm that the code where the query is at is running) and check if the query is producing an error or not, you will never narrow down the problem and find what's causing it. it's also possible that your code is inserting a row, but its not where you are looking for it at. that you are specifying the database name in the insert query means that the insert query could be operating on a different database than the one you think it is from the connection code. i tried your last posted code and it did run to send the email, display the success message, and insert the row in the database table. the needed step would be for you to add code that checks if the query is failing or not and if it is failing, what the mysql error is. -
Need help posting to mysql and sending email from form
mac_gyver replied to gabbymiles's topic in PHP Coding Help
you need to form the sql query statement in a php variable, then echo or var_dump that variable so that you know what the sql actually is. you also need to check for and handle any query errors. note: you cannot guarantee that getting the highest id from a database table, incrementing it, and inserting it in a new row in the database table will produce unique numbers. you will eventually get a collision where two or more concurrent instances of your script are running and try to insert the same value. -
Need help posting to mysql and sending email from form
mac_gyver replied to gabbymiles's topic in PHP Coding Help
it's all one statement. it doesn't matter how many lines it's on in the file. or just use arrays for the errors and data and avoid all that typing for each different form. -
the biggest issue appears to be that the closing </div> for this - <div class="tab-content">, is not after the end of the tabbed content. the closing </div> is on line 288, which is before the tasks and estatus panes. you also have some extra/mis-matched </div> tags. what exact code are you using to accomplish the tabbing (so that someone here could reproduce the problem using your code without making something up that may not be the same as what you are using) and validating the resultant web page at validator.w3.org would help with things like the extra </div> tags.
-
except that php variables are parsed and replaced with their value when used inside of an overall double-quoted string or when using heredoc string syntax, resulting in a minimum of syntax/context changes to use php variables as part of a string. concatenation results in far more errors, both php syntax and html syntax (the OP currently is missing quotes around the title=... attribute value in the table header section) for those who don't clearly yet know which of the syntax is there for the php and which is there for the html/css/javascript markup.
-
this is yet another question we cannot answer, due to the multiple different ways code could be written to accomplish any task, without knowing what the code is. if the code is general purpose and data driven, there will be a definition somewhere (hopefully in a database table) that defines all the form fields and all information about each of them - display legend, field type, required, css style selector, validation rules, ..., that controls the production of the form fields and the processing of any form submission.
-
your output is probably only showing one line because the html is broken. when you moved the array_sum($arr) from the end of the row to the cell with the tank_name, you commented out the </tr> tag. if you are trying to style a set of items, you would use a css class selector, not an id selector.
-
How Do I Revise Old Code To Work In New Version?
mac_gyver replied to spock9458's topic in PHP Coding Help
what output are you getting from the page? and if it's a blank page, what does the 'view source' in your browser show? next, 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 it detects? you can put these settings into your main file, but if your main file contains a php syntax error, which is typically what causes a blank page, it won't help you because your code never runs in this case to affect the error_reporting/display_errors settings. you also have an error in the database connection code error handling. there's no $db variable being used, so there's no $db->connect_error to use in the error handling. edit: and based on examining the code closer and on the color highlighting, you do have a php syntax error due to putting single-quotes inside of an overall single-quoted string. having php's error_reporting/display_errors set as suggested, in the php.ini on your development system, will save you a TON of time when trying to learn, learn anything new, develop code, or debug code. -
you would need to post what your current code is, how the current code is being used in or requested by your page, some example data showing what special characters you are talking about, what output you got from that example data, and what problem, symptom, or error you get in your application due to that output.
-
see the json_encode() function. it will produce the output you are manually piecing together. make an array of arrays of all the rows, then just use - echo json_encode($your_array);
-
you need to stop creating new threads for this and read what has already been posted. you were told in the first thread that the code that dynamically outputs the imaged based on the id in the link, isn't the code you need to change. you need to change the code that's producing the links so that it produces a link that contains the highest id.
-
starting with the line that runs your sql query, the following is all that you need (untested) to produce the result - $result = $conn->query($sql); // run the query $rows = $result->fetch_all(MYSQLI_ASSOC); $data = array(); foreach ($rows as $row) { $data[$row['short_name_i18n']][$row['nickname']] = ($row['combination_exists'] == 1); } if(empty($data)){ echo "Please select again, no players found matching your search"; } else { foreach($data as $tank_name=>$arr){ echo "<tr><td width='167'>".$tank_name."</td>"; // tank name as row label foreach($arr as $nickname=>$element){ // output the data for each cell - you apparently have two images 0.png and 1.png echo "<td><img src='./img/{$element}.png' height='20' width='20' title='$nickname'></td>"; } echo "<td>". array_sum($arr) ."</td></tr>"; } } ?> </table> another recommendation - only SELECT the columns in your sql statement that you are using the data from. based on what you have shown in this thread, the select part of the query only needs to be - SELECT tank_list.short_name_i18n, player_list.nickname, garage_list.tank_id IS NOT NULL AS combination_exists
-
you may want to revisit the last post in your previous thread where that sql query was developed - ^^^ doing what was shown in the code in that last post to store the data into an array will greatly simplify the code that outputs the table. you will just need to use a foreach loop to loop over the main array. the key is the tank name, the value is an array of data for the row. then just loop over the data for each row with another foreach loop. edit: to get the sum of the not null values, you can use php's array_sum() on the array of data. you should also never use the @ error suppressor in your code. if you were getting errors from those statements, you would want to know so that you could correct the problem that was causing them.
-
what have you tried? we can help you with your attempted code, but only after you have made an honest attempt. if you are planning on just copy/pasting something together and dumping it on the forum with an 'it doesn't work', you won't get any more of a response than you already have. if you are not at the point where you understand enough about the code or the process, so that you can even make an attempt at integrating the recaptcha check code into the correct location in your existing application, and testing the result to make sure it does what you expect, you need to instead go and study a basic php book/comprehensive tutorial. we are not here to tell you what and where to type something in your code to do what you want or to write your code for you. if you need that level of assistance, you are not ready to do this thing called programming and should just hire someone to do this for you.
-
update the data in the database from the HTML form
mac_gyver replied to sigmahokies's topic in PHP Coding Help
except that your form's action="insert.php" attribute is submitting to insert.php, not update.php. -
How to obtain last id number, to submit in Picasso for App..
mac_gyver replied to dave204's topic in PHP Coding Help
perhaps you missed this information - this assumes you are dynamically producing the html where the images links are at using php code. -
update the data in the database from the HTML form
mac_gyver replied to sigmahokies's topic in PHP Coding Help
your link should only contain the id, not all of the data. if you were doing this for real, ALL external data must be validated before you can use it. by only passing the id in the link, you only have to validate one value, a positive integer greater-than zero. it would appear you are working on the U part of a CRUD (Create, Read, Update, Delete) exercise. the 'work-flow' steps should be - 1) retrieve a list of data and output an 'edit' link for each record. this link should only identify which record the link corresponds to. 2) in the 'edit' page display code, condition/validate the id, and retrieve the data from the database that the id corresponds to. populate the form field values with the retrieved data. this form should use method = 'post' since it will be altering data on the server. 3) in the 'edit' page form processing code, check that the correct post method form was submitted, validate all the input data, and if there are no validation errors, use the data in an UPDATE query. if there are validation errors, you would display them when you re-display the form so that the user can correct any problems with the submitted data. you should always have some type error handling for database queries, so that you will know if and why they are failing. you should also have php's error_reporting set to E_ALL and for development/debugging have display_errors set to ON and when on a live server, have display_errors set to OFF and log_errors set to ON. if your code already had validation logic and separate error messages for each of the expected input data values and error handling for database queries, it (your code) would likely be telling you why it is failing. also, if you were doing this for real, you would have a user/permission check to insure that the current visitor is authorized to perform each of the three steps of this work-flow and that for any id value, that the visitor is authorized to update the data for that id. -
if the two values are being used in a setcookie() or a session_set_cookie_params() statement or in individual ini_set() statements for the session cookie parameters, the first one means the variations of the domain that the cookie will match and the second one is the path after the domain that the cookie will match. you can find specific information about these two settings in the php.net documentation for the setcookie() or session_set_cookie_params() statements. http:// is not part of a domain. it's a protocol and would not be part of the cookie settings. the path would typically be a / to match all paths after the domain. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying all the errors it detects? this is usually the first step that helps pin down what is causing a problem.
-
How to obtain last id number, to submit in Picasso for App..
mac_gyver replied to dave204's topic in PHP Coding Help
the code you posted at the start of this thread is responsible for dynamically outputting a (one) requested image to the browser/client. you would not change this code (other than to update it and make it secure.) the code you would change is where the image links are being produced. -
you must ALWAYS check for and handle query errors. there are multiple possible reasons that any query can fail. for some quick debugging, just echo mysqli_error($mysqli); on the next line after your mysqli_query() statement, assuming you have a valid database connection in $mysqli. 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?
-
your query isn't matching any row(s). for this condition, which isn't a query error, the ->fetch() method returns a boolean false and the ->fetchAll() method returns an empty array. do the two form variables contain what you expect? are you using the same hashing method on the password when trying to login as when the account was registered (note: md5() is not suitable for hashing passwords. see the password_hash()/password_verify() functions.) is your pass field in the database table large enough to hold the hashed password? and in your viewProtectedArea() method, the catch block for the pdo exception needs to do SOMETHING with the error information . just listing the $exc->getMessage(); on a line doesn't do anything with the value. you should log the error information on a live server and display the information when developing/debugging. if you use php's trigger_error() statement, rather than an exit()/die() statement to handle the error message, it uses php's error_reporting/display_errors/log_errors settings to control where the error information goes to. edit: you would want to use something like this to handle the pdo exception message - trigger_error("Query: $query, Error: {$e->getMessage()}, File: {$e->getFile()}, Line: {$e->getLine()}"); you should be forming your sql statement in a php variable, i.e. $query in this example, so that you can include it in the error handling.
-
the answer is it depends. it depends on if they provided a default admin account or on what the admin side code is doing. you would need to investigate what if anything was stored in the any database tables associated with authentication/permissions or what the code is doing to identify an admin login. without knowing what script you are using, there's no way of providing any definitive answer due to the multiple different possible ways any one thing could be accomplished in a program.
-
that particular error is because you cannot bind sql syntax. you can only bind data values. your uname='$user' OR uname='$user' ... syntax cannot be bound into the query. you don't even need the section of code where the error is at. you should be JOINing the user table to the friends table to get the avatar in the same query where you are getting the friends. in fact, all the queries you have shown can be replaced with one query (you would randomize the two different sections of the results, assuming you really want to randomize anything, by pre-processing the rows in your php code to store the two different sections of the results in their own array, then randomize each of those arrays in the php code.) your code also has a problem with the first query. you cannot bind ONE parameter to multiple place-holders when using prepared queries. you would need to use two differently named place-holders and bind the $uname_s variable twice. the reason you aren't getting any php/mysql errors is because your pdo instance is emulating prepares and for emulated prepares, you can bind one parameter to multiple same-name place-holders (thanks php, NOT, for being consistent and doing what the documentation states.)
-
Fatal error: Call to undefined function: filter_input()
mac_gyver replied to keaauBoy's topic in PHP Coding Help
the OP's phpinfo() output lists a Windows 7 Pro operating system, which is probably his development system, not the web host where he is having the error at. so, what that output from a phpinfo() statement on your web hosting or was that on your localhost xampp system? -
Trouble with Joining Tables in prepared select statement
mac_gyver replied to BuildMyWeb's topic in MySQL Help
in your else {} logic, that corresponds to a failed prepare statement, the error information would be available in $db_connect->error, not in $stmt->error.